bind_param收到错误(对我来说似乎不合逻辑)

时间:2013-09-17 20:31:00

标签: php mysqli bind

这对我来说似乎没有意义。这实际上是错的???我看过其他人的工作,他们和我一样有类型的bind_param,就像这个例子一样:

php, mysqli-stmt.bind-param]: Number of elements in type definition string doesn't match number of bind variables

我这里有23,和23个值(是的,我单独计算,甚至按下Dreamweaver上的输入以确保)。为了安全起见,我甚至尝试过46:

$stmt= $con->prepare("INSERT INTO form_corpo_test (compagnie, telephone, site_web, texte_fr, texte_en, categories, profil_exposant, stands_du_manufacturier, pourcentage_quebec, pourcentage_canada, pourcentage_usa, pourcentage_autre, exporte, exporte_souhaite, produits_vert, nouveau_produits, nom, courriel, telephone_ressource, personne_ressource_c_toi, autre_personne_ressource, autre_courriel, autre_telephone)
VALUES
('$_POST[company]','$_POST[phone]','$_POST[website]','$_POST[messagefr]','$_POST[messageen]','$str','$_POST[profession]','$_POST[manufacturiers_stand]','$_POST[percent_quebec]','$_POST[percent_canada]','$_POST[percent_usa]','$_POST[percent_autre]','$_POST[bt_export]','$_POST[bt_export_souhaite]','$_POST[bt_prod_verts]','$_POST[bt_new_prod]','$_POST[name]','$_POST[email]','$_POST[resource_phone]','$_POST[personne_ressource]','$_POST[backup_name]','$_POST[backup_email]','$_POST[backup_phone]')");



$stmt->bind_param("sssssssssssssssssssssss", $compagnie, $telephone, $site_web, $texte_fr, $texte_en, $categories, $profil_exposant, $stands_du_manufacturier, $pourcentage_quebec, $pourcentage_canada, $pourcentage_usa, $pourcentage_autre, $exporte, $exporte_souhaite, $produits_vert, $nouveau_produits, $nom, $courriel, $telephone_ressource, $personne_ressource_c_toi, $autre_personne_ressource, $autre_courriel, $autre_telephone);

然后我尝试了这个(因为电话号码是整数)

sissssssiiiissssssisssi

两个输出此错误:

  

警告:mysqli_stmt :: bind_param()[mysqli-stmt.bind-param]:Number of   变量与预准备语句中的参数数量不匹配   /home/product/public_html/sidim.com/formulaires/processForm-test.php   在第77行

编辑3

我现在有这个: $ con> query(“INSERT INTO form_corpo_test SELECT * FROM *”);

$stmt = $con->prepare("INSERT INTO form_corpo_test VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");

$stmt->bind_param('sissssssiiiissssssisssi', $compagnie, $telephone, $site_web, $texte_fr, $texte_en, $categories, $profil_exposant, $stands_du_manufacturier, $pourcentage_quebec, $pourcentage_canada, $pourcentage_usa, $pourcentage_autre, $exporte, $exporte_souhaite, $produits_vert, $nouveau_produits, $nom, $courriel, $telephone_ressource, $personne_ressource_c_toi, $autre_personne_ressource, $autre_courriel, $autre_telephone);   // bind $compagnie etc. to the parameter

这仍然会错误输出

  

致命错误:在非对象中调用成员函数bind_param()   /home/product/public_html/******/*******/processForm-test.php在线   83

这是指:

$stmt->bind_param('sissssssiiiissssssisssi', $compagnie, $telephone, $site_web, $texte_fr, $texte_en, $categories, $profil_exposant, $stands_du_manufacturier, $pourcentage_quebec, $pourcentage_canada, $pourcentage_usa, $pourcentage_autre, $exporte, $exporte_souhaite, $produits_vert, $nouveau_produits, $nom, $courriel, $telephone_ressource, $personne_ressource_c_toi, $autre_personne_ressource, $autre_courriel, $autre_telephone);   // bind $compagnie etc. to the parameter

如果到目前为止有任何问题,请务必知道。我现在将更深入地查看u_mulder的帖子。

1 个答案:

答案 0 :(得分:0)

php manual中显示了如何绑定params:

$stmt = mysqli_prepare($link, "INSERT INTO CountryLanguage VALUES (?, ?, ?, ?)");
mysqli_stmt_bind_param($stmt, 'sssd', $code, $language, $official, $percent);

看到那个问号?每个问号都将替换为bind_param中的参数。因此,您的查询应如下所示:

$stmt= $con->prepare("INSERT INTO form_corpo_test (compagnie,... autre_telephone) VALUES (?, ?, ?, ?, ?, ?, ?, ....."); // 26 ?-signs
$stmt->bind_param("sssssssssssssssssssssss", $compagnie, $telephone.. ); // your params here
相关问题