Jump to content

error with mysql code


thetoolman

Recommended Posts

Hi there,

 

I am getting this error with the following code.

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY dateposted' at line 1

 

I was told that I need to define

 

$row['id'] 

 

 

in this line:

 

blog_id = " . $row['id'] . " 

 

But I am not sure how to do so. Does anyone have any ideas why I am getting that error?

 

This is my code:

 

$result = mysql_query($sql); 
$row = mysql_fetch_assoc($result); 
echo "<h1>" . $row['subject'] . "</h1>"; 
echo "<h3>Posted in: <a href='view_category.php?id=" . $row['cat_id'] . "'>" . $row['cat'] . "</a><br /> on " . date("l jS F Y", strtotime($row['dateposted'])) . "at " . date("H:i a", strtotime($row['dateposted']))  . "</h3><br />"; 
echo nl2br($row['body']); 

$comments_sql = "SELECT name, comment FROM comments WHERE blog_id = " . $row['id'] . " ORDER BY dateposted;"; 
$comments_result = mysql_query($comments_sql); 
while($comments_row = mysql_fetch_array($comments_result)){ 
echo "<h1>Commented by: " .  $comments_row['name'] . "</h1><h3>on " . date("l jS F Y", strtotime($row['dateposted'])) . "at " . date("H:i a", strtotime($row['dateposted']))  . "</h3><br /><h3>" . $comments_row['comment'] . "</h3><div class='dotted_div'></div>"; 
} 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/137110-error-with-mysql-code/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.