###エラー内容
Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in /home/sample/www/php/index.php on line 56
データベースにデータを保存しようとするとエラーが起きます。なぜでしょうか?
ご教授宜しくお願いします。
###コード
php
1 2$dsn = 'mysql:host=mysql.db.sakura.ne.jp;dbname=coment;charset=utf8'; 3 $user = ''; 4 $password = ''; 5 6//エラーメッセージの初期化 7$errors = array(); 8 9 10 11//パスワードのハッシュ化 12$Hash = test; 13$url='test1'; 14 15//ここでデータベースに登録する 16try{ 17 18 $dbh = new PDO($dsn, $user, $password); 19 $statement = $dbh->prepare("INSERT INTO URL (URL) VALUES (:url)"); 20 21 if($statement){ 22 $url='test1'; 23 //プレースホルダへ実際の値を設定する 24 $statement->bindValue(':URL', $url, PDO::PARAM_STR); 25 26 if(!$statement->execute()){ 27 $errors['error'] = "登録失敗しました。"; 28 } 29 30 //データベース接続切断 31 $dbh = null; 32 } 33 34 }catch (PDOException $e){ 35 print('Error:'.$e->getMessage()); 36 $errors['error'] = "データベース接続失敗しました。"; 37 } 38 39 40 41 42 43 44

回答1件
あなたの回答
tips
プレビュー