PHPとMysqlを使ってPHPから登録情報の変更ができるようにしようとしていますが
下記のエラーの原因がわからないで困っております。
エラーメッセージ:
QueryError: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 '='uuu', email='uuu', lid='uuu', lpw='uuu' WHERE id='38'' at line 1
該当のソースコード:
<?php //exit(); //index.php(登録フォームの画面ソースコードを全コピーして、このファイルをまるっと上書き保存) $id = $_GET["id"]; //echo"GET:".$id; //1. DB接続します try { $pdo = new PDO('mysql:dbname=gs_db;charset=utf8;host=localhost','root',''); } catch (PDOException $e) { exit('データベースに接続できませんでした。'.$e->getMessage()); } //2.データ登録SQL作成 //*以下の2行は同時に記載可能か?それともどちらかのみか? $stmt = $pdo->prepare("SELECT * FROM gs_user_table WHERE id=:id"); //$stmt = $pdo->prepare("DELETE * FROM gs_bm_table WHERE id=:id"); $stmt->bindValue(":id", $id, PDO::PARAM_INT); $status = $stmt->execute(); //3.データ表示 $view=""; if($status==false){ //execute(SQL実行時にエラーがある場合)ここは決まり文句 $error = $stmt->errorInfo(); exit("ErrorQuery:".$error[2]); }else{ //Selectデータの数だけ自動でループしてくれる while以下は元の文 // while( $result = $stmt->fetch(PDO::FETCH_ASSOC)){ // $view .='<p>'; // $view .= '<a href="detail.php?id='.$result["id"].'">'; // $view .= $result["name"]."[".$result["indate"]."]"; // $view .='</a>'; // $view .='</P>'; //$row以下は省略形? $row = $stmt->fetch(); } ?> <!DOCTYPE html> <html lang="ja"> <head> <meta charset="UTF-8"> <title>VRエアロ</title> <link href="css/bootstrap.min.css" rel="stylesheet"> <style>div{padding: 10px;font-size:16px;}</style> </head> <body> <!-- Head[Start] --> <header> <nav class="navbar navbar-default"> <div class="container-fluid"></div> <div class="navbar-header"><a class="navbar-brand" href="select.php">データ一覧</a></div> </nav> </header> <!-- Head[End] --> <!-- Main[Start] --> <!--疑問 action="update.php"--> <form method="post" action="update.php"> <div class="jumbotron"> <fieldset> <legend style=margin-left:200px;>VRエアロ登録変更</legend> <label style=margin-left:170px;>氏名:<input type="text" name="name" value="<?=$row["name"]?>"></label><br> <label style=margin-left:170px;>メール:<input type="text" name="email" value="<?=$row["email"]?>"></label><br> <label style=margin-left:170px;>ID:<input type="text" name="lid" value="<?=$row["lid"]?>"></label><br> <label style="margin-left:170px;">パスワード:<input type="text" name="lpw" value="<?=$row["lpw"]?>"></label><br> <input type="submit" value="送信" style="margin-left:250px;"> <input type="hidden" name="id" value="<?=$id?>"> </fieldset> </div> </form> <!-- Main[End] --> </body> </html>
以下が、update.phpのコードです。
<?php //以下、関数を利用する宣言 include~ include("functions.php"); //1.POSTでParamを取得 $id = $_POST["id"]; $name = $_POST["name"]; $email = $_POST["email"]; $lid = $_POST["lid"]; $lpw = $_POST["lpw"]; //2. DB接続します(エラー処理追加) $pdo = db_con(); //以下が関数の中身: //try { // $pdo = new PDO('mysql:dbname=gs_db;charset=utf8;host=localhost','root',''); //} catch (PDOException $e) { // exit('DbConnectError:'.$e->getMessage()); //} //3.UPDATE gs_user_table SET ....; で更新(bindValue) //基本的にinsert.phpの処理の流れです。 $stmt = $pdo->prepare("UPDATE gs_user_table name=:name, email=:email, lid=:lid, lpw=:lpw WHERE id=:id"); $stmt->bindValue(':id', $id, PDO::PARAM_INT);//一度vindValueに入れてから上のprepareに代入 $stmt->bindValue(':name', $name, PDO::PARAM_STR); $stmt->bindValue(':email', $email, PDO::PARAM_STR); $stmt->bindValue(':lid', $lid, PDO::PARAM_STR); $stmt->bindValue(':lpw', $lpw, PDO::PARAM_STR); //$stmt->bindValue(':id', $id, PDO::PARAM_INT); $status = $stmt->execute();//実行 if($status==false){ queryError($stmt); }else{ header("Location: select.php");//select.phpへ exit; } ?>
回答2件
あなたの回答
tips
プレビュー