I have the following PHP code for inserting a row into a MySql table.
$addpage = $db->prepare("INSERT INTO content(title,description,body,status,menutitle,menu,date_published,slug,type)VALUES(:title,:desc,:body,:status,:menutitle,:menu,:date,:url,'Page'");
$addpage->bindParam(':title', $_POST["title"]);
$addpage->bindParam(':desc', $_POST["description"]);
$addpage->bindParam(':body', $_POST["body"]);
$addpage->bindParam(':status', $_POST["status"]);
$addpage->bindParam(':menutitle', $_POST["menutitle"]);
$addpage->bindParam(':menu', $_POST["menu"]);
$url = "/".$_POST["url"];
$addpage->bindParam(':url', $url);
$published = date("Y-m-d");
$addpage->bindParam(':date', $published);
if($addpage->execute()){
echo "Success";
}
However PHP is throwing this error:
PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 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' in C:Inetpubvhostschamppaw.co.ukhttpdocsadminprocessaddpage.php:9 Stack trace: #0 C:Inetpubvhostschamppaw.co.ukhttpdocsadminprocessaddpage.php(9): PDO->prepare('INSERT INTO con...') #1 {main} thrown in C:Inetpubvhostschamppaw.co.ukhttpdocsadminprocessaddpage.php on line 9
And I am not sure why because I am pretty sure my syntax is right unless I am missing something simple.
Aucun commentaire:
Enregistrer un commentaire