-2

致命的なエラー: キャッチされない例外 'PDOException' とメッセージ 'SQLSTATE[42000]: 構文エラーまたはアクセス違反: 1064 SQL 構文にエラーがあります。/home/ /domains/ /public_html/new/ .php:140 スタック トレース: #0 /home/ /domains/ /public_html/new/ .php(140): PDOStatement->execute() #1 {main} が 140 行目の /home/ /domains/ /public_html/new/***.php でスローされました

以下に私のコードがあります:

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');
}

どうすればこれを解決できますか、助けてください:-)

たくさんサンクス!

4

3 に答える 3

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)');
于 2015-04-24T23:42:41.900 に答える
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

于 2015-04-24T23:43:19.020 に答える