Im trying to make a small messageboard for my site but I’ve hit a bit of a snag when it comes to replying to a thread. My code has no problem displaying and creating threads but replies are somehow not being inserted into the database table.
My tables are as follows:
threads (id, title, message, author, replies, posted)
replies (id, thread, message, author, posted)
A thread overview is displayed like this:
[php]<?php
$sql = mysql_query(“SELECT * FROM threads ORDER BY posted DESC”);
while($r = mysql_fetch_array($sql)) {
$posted = date(“jS M Y h:i”,$r[posted]);
echo “
$r[title] ($r[replies])
Posted by $r[author] - $posted
”;}
?>[/php]
Clicking the thread link sends the user to msg.php which shows the content of the thread and lets the user post a reply:
[php]<?php
echo “Back…”;
$sql = mysql_query(“SELECT * FROM threads WHERE id = ‘$_GET[id]’”);
while($r = mysql_fetch_array($sql)) {
echo “
$r[title]
”;$posted = “time”;
echo “$r[message]
Posted by $r[author] - $posted
”;
}
echo “
Replies…
”;$sql = mysql_query(“SELECT * FROM replies WHERE thread = ‘$_GET[id]’”);
while($r = mysql_fetch_array($sql)) {
$posted = “time2”;
echo “$r[message]
Posted by $r[author] - $posted
”;
}
?>
Besked:
[/php]
Posting a reply sends the user to newreply.php:
[php]?php
$time = time();
$mah = $_SESSION[‘MM_Username’];
mysql_query(“INSERT INTO replies VALUES(NULL,’$_POST[thread]’,’$_POST[message]’,’$mah’,’$time’)”) or die(mysql_error());
mysql_query(“UPDATE threads SET replies = replies + 1 WHERE id = ‘$_POST[thread]’”);
echo “Reply Posted.
Return”;
?>[/php]
This is the resulting error I get:
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 'id' in /home/virtual/....../public_html/msg.php on line 253 5','blablabla','ja' at line 1
Line 253 of msg.php is:
[php]
[/php]
When I insert values manually into the replies table using phpmyadmin they display just fine in msg.php, so obviously nothing is being inserted by newreply.php.
What am I doing wrong?