-2

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!

Adrian Cid Almaguer
  • 7,815
  • 13
  • 41
  • 63

3 Answers3

4

In your query, take a look at this line:

VALUES (NULL, :meid :title, :category, :ing, :ing_pond, :ing_note, :description, :graad, :time');

note that there is no comma between :meid and :title

this should be

VALUES (NULL, :meid, :title, :category, :ing, :ing_pond, :ing_note, :description, :graad, :time)');
spencer7593
  • 106,611
  • 15
  • 112
  • 140
nomistic
  • 2,902
  • 4
  • 20
  • 36
3

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

Adrian Cid Almaguer
  • 7,815
  • 13
  • 41
  • 63
1

Also take my advaice do not write loops for each sql command

just write once run anywhere

create a php class and send just the command

why you should follow this method ? because you will have same clerical error and problem again and it can make programmers crazy !

however if you prepare your sql command once, you wil not need to write for each sql commend.

PHP PDO

Ahmet ATAK
  • 342
  • 2
  • 13