PHP - MySQL error : Invalid parameter number: parameter was not defined -


i trying use simple mysql insert query parameters in array form. keeps telling me number of parameters wrong :

warning: pdostatement::execute(): sqlstate[hy093]: invalid parameter number: parameter not defined

here code

try { $bdd = new pdo('mysql:host=localhost;dbname=looktallshoes;charset=utf8',  'root', ''); } catch(exception $e) {     die('erreur : '.$e->getmessage()); }  $req = $bdd -> prepare("insert 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'],     )); 

when use hyphen (-) in mysql, thinks doing mathematics - subtracting 1 thing another. using column-names hyphens bad idea in itself, it's possible work around. however, placeholders needs changed. valid pattern [:][a-za-z0-9_]+, means can use alphanumeric values , underscore. columns, need wrapped in backticks. it'd this

$req = $bdd->prepare("insert 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'], )); 

Comments