ODD php warning output - please help!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
reverend_ink
Forum Contributor
Posts: 151
Joined: Sun Apr 20, 2003 1:18 am
Location: Las Vegas | London

ODD php warning output - please help!

Post 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
Jim
Forum Contributor
Posts: 238
Joined: Fri Apr 19, 2002 5:26 am
Location: Near Austin, Texas

Post 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."
reverend_ink
Forum Contributor
Posts: 151
Joined: Sun Apr 20, 2003 1:18 am
Location: Las Vegas | London

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