[英]php error : Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens
I am new to PHP and i have got this error:我是 PHP 的新手,我遇到了这个错误:
Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens致命错误:未捕获的 PDOException:SQLSTATE[HY093]:无效的参数号:绑定变量的数量与标记的数量不匹配
I don't know what is it and how to solve, I searched over the internet but I couldn't find nothing.我不知道它是什么以及如何解决,我在互联网上搜索但我什么也找不到。
My PHP code:我的 PHP 代码:
<?php
#DB connect
$bdd = new PDO('mysql:host=localhost;dbname=alfarabi_website','root','');
#Requete
$requete = $bdd -> prepare('INSERT INTO users (prenom,nom,anniversaire,genre,email,password,role) VALUES(?,?,?,?,?,?,?)');
$requete -> execute(array(isset($_POST['first_name'] ,$_POST['last_name'],$_POST['birthday'],$_POST['gender'],$_POST['email'],$_POST['password'],$_POST['subject'])));
?>
You have to do isset before,你必须先做isset,
$first_name = isset($_POST['first_name'] ? $_POST['first_name'] : null ;
$last_name= isset($_POST['last_name'] ? $_POST['last_name'] : null ;
$birthday= isset($_POST['birthday'] ? $_POST['birthday'] : null ;
Then然后
$requete = $bdd -> prepare('INSERT INTO users (prenom,nom,anniversaire,genre,email,password,role) VALUES(?,?,?,?,?,?,?)');
$requete -> execute(array($first_name ,$last_name,$birthday,.....));
But you will have to check if first_name, last_name or birthday variables are.== null.但是您必须检查 first_name、last_name 或birthday 变量是否为.== null。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.