...

View Full Version : Insert Msg Error



Kev0121
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



<?php
include 'connection.php';
?>

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

<?php
$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";
}
?>


Kevin

Fou-Lu
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum