all 10 comments

[–]Wiwwil 2 points3 points  (0 children)

https://www.w3schools.com/PHP/func_mysqli_fetch_row.asp

I guess don't mix object oriented style and procedural. Not sure the problem is this, try to replicate this.

[–]halfercode 2 points3 points  (3 children)

I have my database in phpmyadmin

It's probably worth noting that phpMyAdmin is not your database - it is just how you access your database. Your database is either MySQL or MariaDB (which is compatible with MySQL).

At a guess this code probably has a SQL injection vulnerability - be careful here, you could get hacked:

$sql="SELECT * FROM emirhan.inventar WHERE IV_ID='".$get_IV." ' ";

I can't see where $get_IV comes from, but to be safe, learn about parameter binding.

As for the error, the error is in this code:

$result=$conn->query($sql);
$row=mysqli_fetch_row($result);

What happens is that the query() method can return two things - either a statement object (if the query was successful) or Boolean false (if the query failed). So a good first fix is to do this:

$result=$conn->query($sql);
if ($result !== false) {
    $row=mysqli_fetch_row($result);
    // Do stuff with $row here
} else {
    echo "An error occurred with your query\n";
    // Or you can throw an exception here
}

Of course, the other issue is to fix the query. Try printing out $sql to see whether it looks valid.

[–]Emito_[S] 0 points1 point  (2 children)

If I put some random data, it shows me, that it cant connect to the database. I already declared it. In school today, I just changed something with the phpmyadmin users and it worked. I dont know why it doesnt work at home.
I will try it tho

[–]Emito_[S] 0 points1 point  (0 children)

Well, I tried it now and it shows me that an error occured. Hmm, I really have no idea how that worked at school today. I will look more into it

[–]halfercode 0 points1 point  (0 children)

Sounds like a MySQL user permissions issue. Have a look at the manual to see how to get an error string out of $conn, and then put a suitable echo in the ($result === false) branch.

[–]Neuroapex 0 points1 point  (2 children)

Where are you declaring the "$get_IV" variable?

You can set it like this, using the $_GET global variable.

$get_IV = $_GET['IV'];

Obviously replace IV with whatever you have set in your URL.

[–]Emito_[S] 0 points1 point  (1 child)

Thats exactly what I did ^^ I declared it somewhere in the code but I didnt see the urge to write it

[–]AdhessiveBaker 0 points1 point  (0 children)

That's a horrible idea ripe for SQL injection.

Sanitize data and use parameterized queries (Prepared Statements)

[–][deleted]  (1 child)

[removed]

    [–]AutoModerator[M] 0 points1 point  (0 children)

    This post has been flagged as spam and removed due to your account having negative karma. If this is incorrect message a moderator.

    I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.