Jump to content

While Loop error.


elmas156

Recommended Posts

I've got the following and I'm receiving this error:

 

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/a3839210/public_html/Testing/main.php on line 37

 

Can anyone tell me what the problem might be?

Thanks very much to anyone who tries to help!

 

<?php
include("db.inc.php");  //connects to database
$result2 = mysql_query("SELECT messid,message,from,read,date FROM messages WHERE id = '$id'");  // line 36
  while ($row2 = mysql_fetch_row($result2)) {  // line 37
  $message = $row2[1];  // line 38
  echo "$message";  // line 39
  }  // line 40
?>

 

Link to comment
https://forums.phpfreaks.com/topic/211538-while-loop-error/
Share on other sites

Your query is failing. I suspect it is because you have a field with the name "from" and MySQL is confusing it with the "FROM" for selecting the table. Enclose your field/table names with back ticks.

 

Try this

$query = "SELECT `messid`, `message`, `from`, `read`, `date`
          FROM `messages`
          WHERE id = '$id'";
$result2 = mysql_query($query)
          or die("Query:<br />$query<br /><br />Error:<br />".mysql_error());

Link to comment
https://forums.phpfreaks.com/topic/211538-while-loop-error/#findComment-1102821
Share on other sites

Where is $id defined ?

 

- Also echo the query and directly fire it on DB console to see if you see any errors

- Use mysql_error() to debug

<?php
include("db.inc.php");  //connects to database
$result2 = mysql_query("SELECT messid,message,from,read,date FROM messages WHERE id = '$id'") or die (mysql_error());  // line 36
     while ($row2 = mysql_fetch_row($result2)) {  // line 37
     $message = $row2[1];  // line 38
     echo "$message";  // line 39
     }  // line 40
?>

Link to comment
https://forums.phpfreaks.com/topic/211538-while-loop-error/#findComment-1102822
Share on other sites

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.