Jump to content

mysql_fetch_array question


sk1tL1L

Recommended Posts

Hello, i've got abit of a problem
[code]
  <?php
include ("config.php");

// Retrieve data from database
$sql= "SELECT * FROM messages WHERE to='$member'";
$result=mysql_query($sql);

while($rows=mysql_fetch_array($result)){
?>
<table width="400" border="1" cellspacing="0" cellpadding="3">
<tr>
<td width="10%"><? echo $rows['from']; ?></td>
<td width="40%"><? echo $rows['message']; ?></td>

</tr>
</table>

<?php
}
mysql_close();
?>[/code]

Whic displays an error:
[code]Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\xampp\htdocs\TFP\messages.php on line 51[/code]

I'm Trying to make my own PM system, it will be great if you can help me with this.
Link to comment
Share on other sites

If the query were returning zero rows, the OP wouldn't get an error, but the while loop wouldn't execute. That error usually occurs when the query has a syntax error. Change the mysql_query() to:
[code]<?php $result=mysql_query($sql) or die("There is a problem with the query: $sql<br>" . mysql_error()); ?>[/code]
Check the error that prints, and fix the problem...

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