954,576 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

PHP Forum Help

I'm making a PHP forum script

But, when ever i try to add a new topic it gives me this error:

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 'desc) VALUES (Test, General Chat, This is a test)' at line 1


Here is where the query is made

<?php
$sub = $_POST['submit'];
if($sub){
?>
<table border='0' cellpadding='5'>
<tr><th colspan='2'>New Topic</th></tr>
<form action='?id=<?php echo $id; ?>' method='POST'>
<tr><td>Topic Name: </td><td><input type='text' name='sub_name'></td><tr>
<tr><td>Topic Description: </td><td><input type='text' name='sub_desc'></td></tr>
<tr><td colspan='2' align='right'><input type='submit' value='Create Topic' name='submit2'></td></tr>
</form>
</table>
<?php
}
$result2 = mysql_query("SELECT * FROM forum_cats WHERE id = '".$id."'");
while($row = mysql_fetch_array($result2)){
$cat_name = $row['cat_name'];
}
$sub2 = $_POST['submit2'];
$name = $_POST['sub_name'];
$desc = $_POST['sub_desc'];
if($sub2){
mysql_query("INSERT INTO forum_sub_cats (sub_cat_name, forum_cat_name, desc) VALUES ($name, $cat_name, $desc)") or die(mysql_error());
echo "Topic Added!";
}


Anyone help?

DealthRune
Light Poster
45 posts since Apr 2009
Reputation Points: 12
Solved Threads: 0
 

You are missing quotes around the string columns in your query.

mysql_query("INSERT INTO forum_sub_cats (sub_cat_name, forum_cat_name, desc) VALUES ('$name', '$cat_name', '$desc')") or die(mysql_error());


Note that you may also need to use mysql_real_escape_string() if you use single quotes in your texts.

pritaeas
Posting Expert
Moderator
5,480 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

Oh

thanks :D

DealthRune
Light Poster
45 posts since Apr 2009
Reputation Points: 12
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You