1
配列形式のパラメータを持つ簡単なMySQL挿入クエリを使用しようとしています。これは、パラメータの数が間違っている私に言って続けて:PHP - MySQLエラー:無効なパラメータ番号:パラメータが定義されていません
警告:PDOStatementに::実行():SQLSTATE [HY093]:無効なパラメータ番号:パラメータはここで
を定義されていませんでしたが、私のコード
ですtry
{
$bdd = new PDO('mysql:host=localhost;dbname=looktallshoes;charset=utf8',
'root', '');
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
$req = $bdd -> prepare("INSERT INTO products (product-title, product-
category, product-source, source-link, product-price, price-before-discount,
product-source-price, height-increase, admin-product-short-description,
admin-product-long-description, large-main-name, square-main-name, other-
photo-1-name, other-photo-2-name, other-photo-3-name, other-photo-4-name)
VALUES(:product-title, :product-category, :product-source, :source-link,
:product-price, :price-before-discount, :product-source-price, :height-
increase, :admin-product-short-description, :admin-product-long-description,
:large-main-name, :square-main-name, :other-photo-1-name, :other-photo-2-
name, :other-photo-3-name, :other-photo-4-name)");
$req->execute(array(
'product-title'=>$_POST['product-title'],
'product-category'=>$_POST['product-category'],
'product-source'=>$_POST['product-source'],
'source-link'=>$_POST['source-link'],
'product-price'=>$_POST['product-price'],
'price-before-discount'=>$_POST['price-before-discount'],
'product-source-price'=>$_POST['product-source-price'],
'height-increase'=>$_POST['height-increase'],
'admin-product-short-description'=>$_POST['admin-product-short-
description'],
'admin-product-long-description'=>$_POST['admin-product-long-
description'],
'large-main-name'=>$_POST['large-main-name'],
'square-main-name'=>$_POST['square-main-name'],
'other-photo-1-name'=>$_POST['other-photo-1-name'],
'other-photo-2-name'=>$_POST['other-photo-2-name'],
'other-photo-3-name'=>$_POST['other-photo-3-name'],
'other-photo-4-name'=>$_POST['other-photo-4-name'],
));
次のようになりたいです。 – Qirel
変数名に「アンダースコア」(_)を使用 –
ダッシュを含む列名については、それぞれバッククォートを使用して引用符を付けます。 –