料理レシピアプリを構築中、エラーに悩まされ詰まっております。
こちらのコードで次のエラーが出ます。
何度見直してもどこが悪いのかわかりません。
構文が悪いと出てますが、どこが悪いかご指摘くださいませんでしょうか?
php
1<?php 2require_once('functions.php'); 3require_once('config.php'); 4ini_set('display_errors', TRUE); 5error_reporting(E_ALL); 6var_dump($_POST); 7 8$user_name = $_POST['user_name']; 9$recipe_name = $_POST['recipe_name']; 10$howto = $_POST['howto']; 11$category = (int) $_POST['category']; 12$difficulty = (int) $_POST['difficulty']; 13$budget = (int) $_POST['budget']; 14 15try{ 16 if(empty($_POST['id'])) throw new Exception('ID不正'); 17 $id = (int) $_POST['id']; 18 19 $dbh = new PDO( 20 DB_DSN, 21 DB_USER, 22 DB_PASS, 23 [ 24 PDO::ATTR_EMULATE_PREPARES, false, 25 PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, 26 PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, 27 ] 28 ); 29 30 $sql = "update recipes set user_name = ?, recipe_name = ?, category = ?, difficulty = ?, budget = ?, howto = ?, where id = ?"; 31 $stmt = $dbh->prepare($sql); 32 $stmt->bindValue(1, $user_name, PDO::PARAM_STR); 33 $stmt->bindValue(2, $recipe_name, PDO::PARAM_STR); 34 $stmt->bindValue(3, $category, PDO::PARAM_INT); 35 $stmt->bindValue(4, $difficulty, PDO::PARAM_INT); 36 $stmt->bindValue(5, $budget, PDO::PARAM_INT); 37 $stmt->bindValue(6, $howto, PDO::PARAM_STR); 38 $stmt->bindValue(7, $id, PDO::PARAM_INT); 39 $stmt->execute(); 40// print_r($stmt->fetchAll()); 41 $dbh = null; 42 echo "レシピの編集が完了しました。"; 43 44} catch(Exception $e){ 45 echo "エラー発生: " . h($e->getMessage(), ENT_QUOTES, 'UTF-8') . "<br>"; 46 die(); 47} 48// <a href="index.php">トップページに戻る</a> 49
エラーと「var_dump($_POST);」の結果。
error
1array(7) { ["user_name"]=> string(7) "paise33" ["recipe_name"]=> string(9) "うんこ" ["category"]=> string(1) "1" ["difficulty"]=> string(1) "1" ["budget"]=> string(3) "334" ["howto"]=> string(13) "tttyyyy mmmm" ["id"]=> string(2) "19" } エラー発生: 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 'where id = 19' at line 1
よろしくお願いします。
回答4件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/12/17 01:21
2018/12/17 01:27
2018/12/17 01:35
2018/12/17 01:37
2018/12/17 02:17