MySQL Query keeps failing (no replies)

This Comment will be submitted for moderation and will not be accessible to other users until it has been approved.
Submitted by programmer on Fri, 08/15/2008 - 20:09.

I have this script I made but I keep getting this error when i load the page:

Query failed: 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 'AND `new_topic` = 1 ORDER BY `post_date`' at line 1

My code for that part:

mysql_connect ($databaseip, $username, $password)

or die ("Couldn't connect to server");

mysql_select_db ($databasename)

or die ("Couldn't Select DB");

$topicq = mysql_query ("SELECT * FROM `ibf_topics` WHERE `forum_id` = ".$forumid." ORDER BY `start_date` DESC")

or die("Query failed: " . mysql_error());

for ($i=0; $i <$topicrows; $i++)

{

$topicrow = mysql_fetch_array($topicq);

$titleid = $topicrow["tid"];

$topictitle = ($topicrow["title"]);

$postq = mysql_query ("SELECT * FROM `ibf_posts` WHERE `topic_id` = ".$titleid." AND `new_topic` = 1 ORDER BY `post_date`")

or die("Query failed: " . mysql_error());

$postfetch = mysql_fetch_array($postq);

$postrow = $postfetch["post"];

$unixdate = $topicrow["start_date"];

$date = date("F jS, Y",$unixdate);

$writter = $topicrow["starter_name"];

$postrow = str_replace('<#EMO_DIR#>', $emoticons, $postrow);

$postrow = str_replace('<#IMG_DIR#>', $img_dir, $postrow);

Can you tell me what is wrong with it?

Thanks!

Post Comment

  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.