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 /home//domains//public_html/new/.php:140 Stack trace: #0 /home//domains//public_html/new/.php(140): PDOStatement->execute() #1 {main} thrown in /home//domains//public_html/new/***.php on line 140
Below you find my code:
if(count($errors) == 0) {
$title = trim($_POST['title']);
$category = trim($_POST['category']);
$ing = trim($_POST['ing']);
$ing_pond = trim($_POST['ing_pond']);
$ing_note = trim($_POST['ing_note']);
$description = trim($_POST['description']);
$time = trim($_POST['time']);
$insert = $dbh->prepare('INSERT INTO recettes (id, id_user, title, category, ing, ing_pond, ing_note, description, graad, time) VALUES (NULL, :meid :title, :category, :ing, :ing_pond, :ing_note, :description, :graad, :time');
$insert->bindParam(':meid', $me['id'], PDO::PARAM_INT);
$insert->bindParam(':title', $title, PDO::PARAM_STR);
$insert->bindParam(':category', $category, PDO::PARAM_STR);
$insert->bindParam(':ing', $ing, PDO::PARAM_STR);
$insert->bindParam(':ing_pond', $ing_pond, PDO::PARAM_STR);
$insert->bindParam(':ing_note', $ing_note, PDO::PARAM_STR);
$insert->bindParam(':description', $description, PDO::PARAM_STR);
$insert->bindParam(':graad', $graad, PDO::PARAM_STR);
$insert->bindParam(':time', $time, PDO::PARAM_STR);
$insert->execute();
$uid = $dbh->lastInsertId();
echo alert('Uw gerecht is succesvol toegevoegd.', 'success');
$added = true;
}else{
echo alert('Er ging wat mis. De volgende dingen gingen fout:<ul><li>' . join('</li><li>', $errors) . '</li></ul>Het gerecht is helaas niet toegevoegd.', 'danger');
}
How do i get this solved, can some please help me :-)
Thnx a lot!
Replace this line:
$insert = $dbh->prepare('INSERT INTO recettes (id, id_user, title, category, ing, ing_pond, ing_note, description, graad, time) VALUES (NULL, :meid :title, :category, :ing, :ing_pond, :ing_note, :description, :graad, :time');
With this line:
$insert = $dbh->prepare('INSERT INTO recettes (id, id_user, title, category, ing, ing_pond, ing_note, description, graad, time) VALUES (NULL, :meid, :title, :category, :ing, :ing_pond, :ing_note, :description, :graad, :time)');
You forget the last )
in your code and a comma ,
between :meid
and :title