SQLSTATE [HY093]:参数号无效:参数未定义...

时间:2015-01-29 23:00:57

标签: php mysql forms insert

我一直在收到SQLSTATE [HY093]错误,但我似乎无法找到它的来源。我试图使用表单的参数将行插入数据库表。

我已经回复了表单中的所有参数,它们都正常工作并正确显示。

$q = "INSERT INTO members (mid, firstname, lastname, username, password, email, phone, street, location, gender, ccnumber, expirymonth, expiryyear) VALUES (NULL, :firstName, :lastName, :username, :password, :email, :phone, :street, :location, :gender, :ccnumber, :expmonth, :expyear);";  
$query = $dbConnect->prepare($q);
    $enc_password = crypt($password,$username);
    //echo 'It is: '.$enc_password.' ';
    //echo 'It is: '.$lastName.' ';
$query->bindParam(":firstname",$firstName);
$query->bindParam(":lastname",$lastName);
    $query->bindParam(":username",$username);
    $query->bindParam(":password",$enc_password);
    $query->bindParam(":email",$email);
$query->bindParam(":phone",$phone);
    $query->bindParam(":street",$street);
    $query->bindParam(":location",$location);
    $query->bindParam(":gender",$gender);
$query->bindParam(":ccnumber",$ccnumber);
    $query->bindParam(":expirymonth",$expmonth);
    $query->bindParam(":expiryyear",$expyear);
    //$query->debugDumpParams();
$result = $query->execute();
return $result;

提前致谢:)!

2 个答案:

答案 0 :(得分:1)

你有骆驼案:

$q = "INSERT ... :firstName, :lastName ...

然后是小写:

$query->bindParam(":firstname",$firstName);
$query->bindParam(":lastname",$lastName);

看起来像是一个区分大小写的问题。

您的查询中也有:

:expmonth, :expyear

然而你将它们绑定为:

$query->bindParam(":expirymonth",$expmonth);
$query->bindParam(":expiryyear",$expyear);

答案 1 :(得分:0)

$查询 - > bindParam(":expirymonth",$ expmonth); $查询 - > bindParam(":expiryyear",$ expyear);

我想,你没有定义' expirymonth'和' expiryyear'在您的查询中。 相反,你称之为':expmonth,:expyear'