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

Link to comment
Share on other sites

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/>";
}

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.