View Full Version : Insert Msg Error

03-07-2009, 04:03 AM
Im getting error when trying to insert something into my database
heres my 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 'To See If Im Pro At Coding :D)' at line 1

and heres my code

include 'connection.php';

<title>Insert Into Blog</title>
<form action = "<?php $_SERVER['PHP_SELF']; ?>" method="POST" name="insert">
<td>Post Title : <input type="text" name="pTitle" /> </td>
<td>Post Author : <input type="text" name="pAuth" /> </td>
<td>Post Content : <br/> <input type="text" name="pContent"/> </td>
<td><input type="submit" name="Submit" value="Done" /> </td>

$title = $_POST['pTitle'];
$author = $_POST['pAuth'];
$content = $_POST['pContent'];

if(isset($_POST['Submit'])) {
$insertData = "INSERT INTO `test` (title,author,content) VALUES ($title, $author, $content)";
$query = mysql_query($insertData) or die(mysql_error());
}else {
echo "Error";


03-07-2009, 05:08 AM
SQL error, not a PHP one. I'll move it to the mysql forum.

$insertData = "INSERT INTO `test` (title,author,content) VALUES ('$title', '$author', '$content')";

Those variables look to be strings. Therefore, you must wrap them in quotations to be treated as strings, otherwise DBMS will attempt to cast them to a double and fail.
Make sure you're properly escaping you're input data with mysql_real_escape_strings, and stripslashing any of the magic_quotes that may or may not be added.