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.

Link to comment
Share on other sites

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>
";
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.