Jump to content

"You have an error in your SQL syntax;" - little help?


Abbeh

Recommended Posts

I'm attempting to install home-coded message boards on a website, and they're working fine - apart from when you try to post.  Then I get this error message:

 

Cannot create topic! 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 ')' at line 1

 

I'm still new to PHP, so I'd appreciate a few tips on why this is happening?  If the code is needed then I can provide.

The first few lines are includes, and then the header code for the layout, they're working fine.  This is the start of message board posting and replies.

 

 

EDITED: This should be all, I think.

 

<?php 

if($msg_id){

if(@$_POST['post_reply']){
	$subject = strip_tags(@$_POST['subject']);
	$body = nl2br(@$_POST['body']);
	$date = date(YmdHis);

	if(!$subject){echo "<tr><td colspan=2><center><font color=red>Invalid Subject!</td></tr>";}
	if(!$body){echo "<tr><td colspan=2><center><font color=red>You must include a message.</td></tr>";exit;}

	@mysql_query("INSERT INTO msg_replies(board_id, subject, body, recent_reply, mid, reply_id) VALUES($board_id, '$subject', '$body', '$date', $mid, $msg_id)")or die("Cannot create topic! " . @mysql_error());
	@mysql_query("UPDATE msg_replies SET recent_reply='$date' WHERE msg_id=$msg_id LIMIT 1")or die("Cannot update topic! " . @mysql_error());
	echo "<tr><td colspan=2><center><font color=red>Message posted!</center></font></td></tr>";
	$body = "";
}

echo "$page_options</td></tr>
<tr><Td colspan=2><b>Post Reply</b></td></tr>
<tr><td>To post a reply to this topic, please fill out the following form. HTML <i>is</i> allowed.
<form action='boards.php?id=$board_id&msg=".@$_GET['msg']."' method=post>
<b>Subject:<br>
<input type=text name='subject' maxlength=75 value='$subject'><br>
Body:<br>
<textarea name='body' rows=10 cols=50></textarea><br><br>
<input type=submit name='post_reply' value='Post it!'></form>
";



// if a messageboard, but no topic, has been selected, display all topics
}elseif($board_id){
if(@$_POST['post_topic']){
	$subject = strip_tags(@$_POST['subject']);
	$body = @$_POST['body'];
	$date = date(YmdHis);

	if(!$subject){echo "<center><font color=red>Invalid Subject!";exit;}
	if(!$body){echo "<center><font color=red>You must include a message.";exit;}

	@mysql_query("INSERT INTO msg_replies(board_id, subject, body, date, recent_reply, mid) VALUES($board_id, '$subject', '$body', '$date', '$date', $mid)")or die("Cannot create topic! " . @mysql_error());
	echo "<center><font color=red>Topic posted!</center></font>";
}

echo "
$page_options</td></tr>
<tr><Td colspan=2><h1 width=500>
<br><b>Post Topic</b></td></tr>
<tr><td>To post a new topic, please fill out the following form. HTML <i>is</i> allowed.
<form action='boards.php?id=$board_id' method=post>
<b>Subject:<br>
<input type=text name='subject' maxlength=75><br>
Body:<br>
<textarea name='body' rows=10 cols=50></textarea><br><br>
<input type=submit name='post_topic' value='Post it!'></form>
";
?>

in the query under 'post_topic' where is $mid filled from?

 

$mid = $_SESSION['mid'];

 

 

 

 

Try...

 

@mysql_query("INSERT INTO msg_replies (board_id, subject, body, recent_reply, mid, reply_id) VALUES ($board_id, '$subject', '$body', '$date', '$mid', '$msg_id')") or die("Cannot create topic! " . @mysql_error());

 

Notice the extra spaces.

 

Thanks, I'll try it!

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.