Warning doesnt make sense?

Im getting this warning
Warning: mysqli_fetch_assoc(): Couldn’t fetch mysqli_result in C:\Users\lurtnowski\webserver\htdocs\DCT\2\power\edit_mdp.php on line 80
I dont know what it means as the query works, but heres my code.
image

1 Like

That query doesn’t look quite right to me.

here it is

$sql = 'SELECT * 
       FROM mdps 
       WHERE mdp_id = '.$mdp_id;

echo $sql;

$result = mysqli_query($conn, $sql);

When I run it

Doesn’t that mean the query is good?

Show us your whole code inside that loop. (No idea how Mitt is seeing the query, as i can’t see it in the first image, which the forum wont let me expand for some reason.)

1 Like

ask for errors:

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

1 Like

EDIT

Should it not be: WHERE 'id' == 'mdp_id';

SQL syntax is slightly different than php syntax. So the answer is no.

I’d still like to see the loop. I have a suspicion you’ve got a mysqli_free_result hiding at the bottom of it that’s screwing you up…

You’re probably a sitting duck for SQL Injection attacks as you’re just plugging the value for $mdp_id directly into the query, you should be using prepared statements

Its a strange warning, here a screewngrab of it on my server

the query works, but I still get the warning, heres the php

<?php
session_start();

if(isset($_SESSION['email'])) { 
include "../conn.php";

$generator_id = (int)$_GET['id'];
	
$sql = 'SELECT * 
       FROM generators 
       WHERE generator_id = '.$generator_id;

//echo $sql;

$result = mysqli_query($conn, $sql);

?>
HTML CODE
...
...
<?php
	if (mysqli_num_rows($result) > 0) {
		
		while($generator_row = mysqli_fetch_assoc($result)) {
		
?>
HTML CODE
<?php
		}
	}
?>	

ok, ive been using
https://www.tutorialrepublic.com/php-reference/php-mysqli-functions.php
for a tutorial, should I not, and use PDO instead?
or follow

This is a good tutorial on PDO.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.