Page 1 of 1

ODD php warning output - please help!

Posted: Mon May 05, 2003 11:17 pm
by reverend_ink
OK I have used this code many times (EVEN on the same server) yet for some reason it isn't working...

Can you tell me why?

Code: Select all

<?php
@mysql_connect($host, $loginname, $password) or die(mysql_error()); 
@mysql_select_db($data) or die('Could not select database'.mysql_error()); 

$result = mysql_query("SELECT * FROM $table ORDER BY id DESC");

while ($row = mysql_fetch_array($result)) &#123;

$row&#1111;'diary_entry'];
$row&#1111;'date'];

echo ("<tr><td align=center valign=middle width=25%><font size=3 face=Verdana,BankGothic Md BT, Arial, Helvetica><b>".$row&#1111;'date']."</b></font></td><td align=left valign=middle><font size=3 face=Verdana,BankGothic Md BT, Arial, Helvetica>".$row&#1111;'diary_entry']."</font></td></tr>");

mysql_free_result($result);

&#125;
?>
The error I get is Warning: 2 is not a valid MySQL result resource in /home/httpd/vhosts/site1/httpdocs/diary.php on line 23

23 is

Code: Select all

while ($row = mysql_fetch_array($result)) &#123;
Thanks

Posted: Mon May 05, 2003 11:42 pm
by Jim
Where is the definition for the variable $table?

Add this underneath that $result = mysql_query();

Code: Select all

if (!$result) {

echo mysql_error();

}
I think the problem is that you aren't defining a table in the code.

If you ARE defining a table, another problem may be that your $table is not surrounded by "..". Try this instead of $table: ".$table."

Posted: Tue May 06, 2003 12:06 am
by reverend_ink
Actually table was defined in a $table = "" statement at the beginning of the script.

I ended up fixing the script by removing

Code: Select all

mysql_free_result($result);
from the equation

Thanks though...

Just working the problem seemed to help find the solution.....