为什么我收到此错误“SQLSTATE [HY093]:参数号无效:参数未定义”?

时间:2017-02-09 13:35:18

标签: php mysql sql

我有这个代码将数据插入MySQL。当我尝试调用函数register_emp()时发生错误。你可以告诉我该怎么做才能解决这种错误。谢谢。

if($user->register_emp($last,$first,$middle,$middle,
                        $address,$contact,$email,$birth,$gender,
                        $status,$citizen,$position,$dependent))
{
    try
    {

        $stmt = $user->runQuery("SELECT MAX(ID) as LastID from employeeprofile");
        $stmt->execute(array());
        $userRow=$stmt->fetch(PDO::FETCH_ASSOC);
        if($stmt->rowCount() == 1)if($stmt->rowCount() == 1){
        $owner=$userRow['LastID'];

        if($user->register_contrib($owner,$sss,$tin,$pagibig,$phil)){
            $user->redirect('admin1.php');
        }
    }

}
catch(PDOException $e)
{
    echo $e->getMessage();
}

}

这是我试图调用的register_emp函数。

public function register_emp($last,$first,$middle,$address,
                            $zip,$contact,$email,$birth,
                            $gender,$status,$citizen,$position,$dependent)
{
    try
    {


        $stmt = $this->conn->prepare("INSERT INTO `proll`.`employeeprofile` 
        (`Lastname`, `Firstname`, `Middlename`, `Address`, `ZIP`, `Contact`, `Email`, `Birthdate`, `Gender`, `Status`, `Citizenship`, `Position`, `Dependent`) VALUES 
        (:last,:first,:middle,:address,:zip,:contact,:email,:birth,:gender,:status,:citizenship,:position,:dependent)");


        $stmt->bindparam(":last", $last);
        $stmt->bindparam(":first", $first);
        $stmt->bindparam(":middle", $middle);
        $stmt->bindparam(":address", $address);
        $stmt->bindparam(":zip", $zip);
        $stmt->bindparam(":contact", $contact);
        $stmt->bindparam(":email", $email);
        $stmt->bindparam(":birth", $birth);
        $stmt->bindparam(":gender", $gender);
        $stmt->bindparam(":status", $status);       
        $stmt->bindparam(":citizen", $citizen); 
        $stmt->bindparam(":position", $position);
        $stmt->bindparam(":dependent", $dependent);


        $stmt->execute();   

        return $stmt;   
    }
    catch(PDOException $e)
    {
        echo $e->getMessage();
    }               
}

1 个答案:

答案 0 :(得分:1)

问题在于公民/公民身份。您正在为prepare语句和绑定使用不同的单词:

$stmt = $this->conn->prepare("INSERT INTO `proll`.`employeeprofile` 
    (`Lastname`, `Firstname`, `Middlename`, `Address`, `ZIP`, `Contact`, `Email`, `Birthdate`, `Gender`, `Status`, `Citizenship`, `Position`, `Dependent`) VALUES 
    (:last,:first,:middle,:address,:zip,:contact,:email,:birth,:gender,:status,:citizenship,:position,:dependent)");

....

    $stmt->bindparam(":citizen", $citizen);

将它们改为同一个词,你会很好。

相关问题