Error in Query?
Posted: Mon Feb 09, 2009 6:34 pm
I honestly cannot find out what is wrong with this code. I'm fairly new at PHP so the variable $i call may be wrong, I'm not sure.
The error I get is
A quick help would be much appreciated
, and remember, I'm new to PHP 
Oh and this is my first post, hopefully not my last. So hi!
Code: Select all
<?
$dbhost = 'localhost';
$dbuser = 'ip2g_*****';
$dbpass = '*****';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
$dbname = 'ip2g_*****';
mysql_select_db($dbname) or die('Could not connect to Database');
for ($i=1;$i<=3;$i++)
{
$query = "SELECT * FROM Posts WHERE postID='$i'";
$result = mysql_query($conn,$query)
or die ("Couldn't Execute Query.");
$row = mysql_fetch_assoc($result);
$postTitle = $row['postTitle'];
$postDate = $row['postDate'];
echo " <li class='menu'>
<a href='about.html'>
<span class='name'>" . $postTitle . "</span>
<span class='comment'>" . $postDate . "</span>
<span class='arrow'></span>
</a>
</li>";
}
?>
... which obviously means the query is wrong. I have 3 entries in the table Posts, and I have made sure the table is spelled correctly in both the mySQL and on this code. Am I calling the variable "$i" incorrectly? How can I fix this?Couldn't Execute Query
A quick help would be much appreciated
Oh and this is my first post, hopefully not my last. So hi!