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