Jump to content

[SMALL ERROR] Why do I get this error? Everything is correct as I can see.


3raser

Recommended Posts

Here is my query and execution code:

 

                                $query = mysql_query("SELECT * FROM answers WHERE to='$to'");

			while($row = mysql_fetch_assoc($query))
			{
				$row['message'] = stripslashes($row['message']);
				echo "Submitted on <b>". $row['date'] ."</b><br/><b><span style='color:green'>". $row['message'] ."</span></b><br/><br/>";
			}

 

Why do I keep getting this:

 

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/a9796960/public_html/qa.php on line 91

 

Everything is correct.

 

picture.png

My guess would be that $to has no value, and the query is failing because of that. Separate the query string from the execution, and echo with any errors it to see what's happening

 

$query = "SELECT * FROM answers WHERE to='$to'";
$result = mysql_query($query) or die( 'Query string: ' . $query . '<br />Failed with error: ' . mysql_error() ); // change die to trigger_error for live sites
while($row = mysql_fetch_assoc($result)) {
   $row['message'] = stripslashes($row['message']);
   echo "Submitted on <b>". $row['date'] ."</b><br/><b><span style='color:green'>". $row['message'] ."</span></b><br/><br/>";
}

My guess would be that $to has no value, and the query is failing because of that. Separate the query string from the execution, and echo with any errors it to see what's happening

 

$query = "SELECT * FROM answers WHERE to='$to'";
$result = mysql_query($query) or die( 'Query string: ' . $query . '<br />Failed with error: ' . mysql_error() ); // change die to trigger_error for live sites
while($row = mysql_fetch_assoc($result)) {
   $row['message'] = stripslashes($row['message']);
   echo "Submitted on <b>". $row['date'] ."</b><br/><b><span style='color:green'>". $row['message'] ."</span></b><br/><br/>";
}

 

Alright, I got this error:

 

Query string: SELECT * FROM answers WHERE to='2'
Failed with error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'to='2'' at line 1

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.