###やりたいこと
DBにデータの追加をしたい。
よろしくお願いします。
###エラー内容
1064You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':text ,:groupid , :userid)' at line 1
###コード
php
1 2if ($mysqli->connect_error){ 3 echo $mysqli->connect_error; 4 exit(); 5}else{ 6 $mysqli->set_charset("utf-8"); 7} 8 9 10 11 //プリペアドステートメント 12 $stmt = $mysqli -> prepare("INSERT INTO message (Message,GroupID,UserId) VALUES (:text ,:groupid , :userid)"); 13 14 if($stmt){ 15 $stmt->bindParam(':text', $name, PDO::PARAM_STR); 16 $stmt->bindParam(':groupid', $id, PDO::PARAM_STR); 17 $stmt->bindParam(':userid', $userid, PDO::PARAM_STR); 18 19 20 if($stmt->execute()){ 21 echo htmlspecialchars($text, ENT_QUOTES, 'UTF-8')."さんで登録いたしました。"; 22 }else{ 23 echo $stmt->errno . $stmt->error; 24 } 25 26 //ステートメント切断 27 $stmt->close(); 28 }else{ 29 echo $mysqli->errno . $mysqli->error; 30} 31// データベース切断 32$mysqli->close();
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。