Possible Duplicate:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result
I’m getting this error message:
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /…/…/…./index.php on line 215
Index.php code:
if (isset($_GET['post_id']) && $_GET['post_id'] != '')
{
$p_id = (int) $_GET['post_id'];
$sql= mysql_query("SELECT * FROM news_post WHERE post_id = '$p_id' AND block = 0 LIMIT
$offset, $rowsperpage") or mysql_error();
}
else
{
$sql= mysql_query("SELECT * FROM news_post WHERE block = 0 ORDER BY post_id DESC
LIMIT $offset, $rowsperpage ") or mysql_error();
}
while ($rel = mysql_fetch_assoc($sql)) (Note: this is Line 215)
{
$id = intval($rel['post_id']);
$sub = ucfirst($rel['subject']);
$imgname = htmlentities($rel['img_name']);
$img = htmlentities($rel ['image']);
$msg = $rel['message'];
$date = htmlentities($rel['date']);
$poster = htmlentities($rel['poster']);
$cat_id = intval($rel['cat_id']);
$cat_name = htmlentities($rel['cat_name']);
In my Localhost, it’s Ok, it’s doesn’t show any error message but when up this to my server then it’s show error..
What is wrong in my code? can anyone tell me the right direction…
Thanks a lot.
You have an error in the following line
The function
mysql_error()returns a string, so whenmysql_query()fails, the$sqlvariable will contain whatever error was thrown. Later, you tread this string variable as a MySQL resource.Instead, what you’re probably trying to do, is to print out whatever string
mysql_error()returns and terminate the script. This is usually accomplished withdie()in these kinds of scripts.So, if you instead use the following, the script will terminate and output the error, should one occur.
Finally, you claim that the above works on your server, but not on localhost, which is not correct. If an error occured on your server, you would get the same behavior.