SQLSTATE [HY093]错误

时间:2016-07-22 03:22:35

标签: php sql

我正在尝试在PHP中运行以下内容:

$stmt = $db_con->prepare("SELECT * FROM users WHERE email=:email");
$stmt->execute(array(":email"=>$user_email));
$count = $stmt->rowCount();

if($count==0){

$stmt = $db_con->prepare("INSERT INTO users(username,email,password,ip)VALUES(:uname, :email, :password, :ip)");
$stmt->bindParam(":username",$username);
$stmt->bindParam(":email",$useremail);
 $stmt->bindParam(":password",$hasheduserpassword);
$stmt->bindParam(":ip",$userip);

结果,我收到以下错误:

SQLSTATE[HY093]: Invalid parameter number: parameter was not defined

3 个答案:

答案 0 :(得分:1)

在查询中,您在设置名为username的参数时定义了uname 尝试

$stmt = $db_con->prepare("INSERT INTO users(username,email,password,ip)VALUES(:username, :email, :password, :ip)");

答案 1 :(得分:0)

您的error就在这里

  $stmt = $db_con->prepare("INSERT INTO users(username,email,password,ip)VALUES(:uname, :email, :password, :ip)");
 //   $stmt->bindParam(":username",$username);// this shoud be uname
 $stmt->bindParam(":uname",$username);

答案 2 :(得分:0)

错误在这里:

VALUES(:uname,

$stmt->bindParam(":username",$username);

MySql正在寻找:username,但由于您将其命名为:uname,因此无法找到它。

两者必须匹配。