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
reverend_ink
Forum Contributor
Posts: 151 Joined: Sun Apr 20, 2003 1:18 am
Location: Las Vegas | London
Post
by reverend_ink » Mon May 05, 2003 11:17 pm
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)) {
$rowї'diary_entry'];
$rowї'date'];
echo ("<tr><td align=center valign=middle width=25%><font size=3 face=Verdana,BankGothic Md BT, Arial, Helvetica><b>".$rowї'date']."</b></font></td><td align=left valign=middle><font size=3 face=Verdana,BankGothic Md BT, Arial, Helvetica>".$rowї'diary_entry']."</font></td></tr>");
mysql_free_result($result);
}
?>
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)) {
Thanks
Jim
Forum Contributor
Posts: 238 Joined: Fri Apr 19, 2002 5:26 am
Location: Near Austin, Texas
Post
by Jim » Mon May 05, 2003 11:42 pm
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 » Tue May 06, 2003 12:06 am
Actually table was defined in a $table = "" statement at the beginning of the script.
I ended up fixing the script by removing
from the equation
Thanks though...
Just working the problem seemed to help find the solution.....