Php 获取错误:SQLSTATE[HY093]:参数编号无效:未定义参数

Php 获取错误:SQLSTATE[HY093]:参数编号无效:未定义参数,php,mysql,pdo,Php,Mysql,Pdo,我知道这个错误是什么意思,但我不知道它为什么会出现。我已经检查了变量名、PDO变量名、数据库中的表名,但仍然没有检查任何内容 如果我将insert复制到phpMyAdmin中,它将运行得很好。如果我将所有变量从$this->更改为'abcd',则会出现相同的错误 我真的不知道发生了什么 错误: class Users { public $username = null; public $password = null; public $useremail = null; public $

我知道这个错误是什么意思,但我不知道它为什么会出现。我已经检查了变量名、PDO变量名、数据库中的表名,但仍然没有检查任何内容

如果我将insert复制到phpMyAdmin中,它将运行得很好。如果我将所有变量从$this->更改为'abcd',则会出现相同的错误

我真的不知道发生了什么

错误:

class Users {
 public $username = null;
 public $password = null;
 public $useremail = null;
 public $steam_id = null;
 public $salt = "Zo4rU5Z1YyKJAASY0PT6EUg7BBYdlEhPaNLuxAwU8lqu1ElzHv0Ri7EM6irpx5w";

 public function __construct( $data = array() ) {
     if( isset( $data['username'] ) ) $this->username = stripslashes( strip_tags( $data['username'] ) );
     if( isset( $data['password'] ) ) $this->password = stripslashes( strip_tags( $data['password'] ) );
     if( isset( $data['useremail'] ) ) $this->useremail = stripslashes( strip_tags( $data['useremail'] ) );
     if( isset( $data['steam_id'] ) ) $this->steam_id = stripslashes( strip_tags( $data['steam_id'] ) );
 }

 public function storeFormValues( $params ) {
    //store the parameters
    $this->__construct( $params ); 
 }
 public function register() {
    $correct = false;

        try {
            $con = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
            $con->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );

            $sql1 = "SELECT * FROM users WHERE user_name = :username LIMIT 1";
            $polacz1 = $con->prepare( $sql1 );
            $polacz1->bindValue( "username", $this->username, PDO::PARAM_STR );
            $polacz1->execute();
            $row = $polacz1->fetch();
            $sql2 = "SELECT * FROM users WHERE user_email = :useremail LIMIT 1";
            $polacz2 = $con->prepare( $sql2 );
            $polacz2->bindValue( "useremail", $this->useremail, PDO::PARAM_STR );
            $polacz2->execute();
            $row1 = $polacz2->fetch();
            $sql3 = "SELECT * FROM users WHERE steam_id = :steam_id LIMIT 1";
            $polacz3 = $con->prepare( $sql2 );
            $polacz3->bindValue( "steam_id", $this->steam_id, PDO::PARAM_STR );
            $polacz3->execute();
            $row2 = $polacz3->fetch();
            if($row == NULL){
                if($row1 == NULL){
                    if($row1 == NULL){
                        $checksum = bin2hex(mcrypt_create_iv(22, MCRYPT_DEV_URANDOM));
                        $sql = "INSERT INTO users(user_name, user_email, user_pass, steam_id, email_hash) VALUES(:username, :useremail, :password, :steamid, :emailhash)";

                        $polacz = $con->prepare( $sql );
                        $polacz->bindValue( ":username", $this->username, PDO::PARAM_STR );
                        $polacz->bindValue( ":useremail", $this->useremail, PDO::PARAM_STR );
                        $polacz->bindValue( ":password", hash("sha256", $this->password . $this->salt), PDO::PARAM_STR );
                        $polacz->bindValue( ":steamid", $this->steam_id, PDO::PARAM_STR );
                        $polacz->bindValue( ":emailhash", $checksum, PDO::PARAM_STR );
                        $polacz->execute();

return '<div class="alert alert-success" role="alert">Zostałeś pomyślnie zarejestowany. Sprawdź podany adres email i aktywuj swoje konto!</div>';




                        //return "Rejestracja przebiegła pomyślnie, możesz się zalogować.";
                    } else return '<div class="alert alert-danger" role="alert">Podany steam ID już istnieje.</div>';
                }
                else
                {
                    return '<div class="alert alert-danger" role="alert">Podany e-mail już istnieje.</div>';
                }
            }
            else 
            {
                return '<div class="alert alert-danger" role="alert">Podany użytkownik już istnieje.</div>';
            }
        }catch( PDOException $e ) {
            return $e->getMessage();
        }
 }
 }
SQLSTATE[HY093]:参数编号无效:未定义参数

代码:

class Users {
 public $username = null;
 public $password = null;
 public $useremail = null;
 public $steam_id = null;
 public $salt = "Zo4rU5Z1YyKJAASY0PT6EUg7BBYdlEhPaNLuxAwU8lqu1ElzHv0Ri7EM6irpx5w";

 public function __construct( $data = array() ) {
     if( isset( $data['username'] ) ) $this->username = stripslashes( strip_tags( $data['username'] ) );
     if( isset( $data['password'] ) ) $this->password = stripslashes( strip_tags( $data['password'] ) );
     if( isset( $data['useremail'] ) ) $this->useremail = stripslashes( strip_tags( $data['useremail'] ) );
     if( isset( $data['steam_id'] ) ) $this->steam_id = stripslashes( strip_tags( $data['steam_id'] ) );
 }

 public function storeFormValues( $params ) {
    //store the parameters
    $this->__construct( $params ); 
 }
 public function register() {
    $correct = false;

        try {
            $con = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
            $con->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );

            $sql1 = "SELECT * FROM users WHERE user_name = :username LIMIT 1";
            $polacz1 = $con->prepare( $sql1 );
            $polacz1->bindValue( "username", $this->username, PDO::PARAM_STR );
            $polacz1->execute();
            $row = $polacz1->fetch();
            $sql2 = "SELECT * FROM users WHERE user_email = :useremail LIMIT 1";
            $polacz2 = $con->prepare( $sql2 );
            $polacz2->bindValue( "useremail", $this->useremail, PDO::PARAM_STR );
            $polacz2->execute();
            $row1 = $polacz2->fetch();
            $sql3 = "SELECT * FROM users WHERE steam_id = :steam_id LIMIT 1";
            $polacz3 = $con->prepare( $sql2 );
            $polacz3->bindValue( "steam_id", $this->steam_id, PDO::PARAM_STR );
            $polacz3->execute();
            $row2 = $polacz3->fetch();
            if($row == NULL){
                if($row1 == NULL){
                    if($row1 == NULL){
                        $checksum = bin2hex(mcrypt_create_iv(22, MCRYPT_DEV_URANDOM));
                        $sql = "INSERT INTO users(user_name, user_email, user_pass, steam_id, email_hash) VALUES(:username, :useremail, :password, :steamid, :emailhash)";

                        $polacz = $con->prepare( $sql );
                        $polacz->bindValue( ":username", $this->username, PDO::PARAM_STR );
                        $polacz->bindValue( ":useremail", $this->useremail, PDO::PARAM_STR );
                        $polacz->bindValue( ":password", hash("sha256", $this->password . $this->salt), PDO::PARAM_STR );
                        $polacz->bindValue( ":steamid", $this->steam_id, PDO::PARAM_STR );
                        $polacz->bindValue( ":emailhash", $checksum, PDO::PARAM_STR );
                        $polacz->execute();

return '<div class="alert alert-success" role="alert">Zostałeś pomyślnie zarejestowany. Sprawdź podany adres email i aktywuj swoje konto!</div>';




                        //return "Rejestracja przebiegła pomyślnie, możesz się zalogować.";
                    } else return '<div class="alert alert-danger" role="alert">Podany steam ID już istnieje.</div>';
                }
                else
                {
                    return '<div class="alert alert-danger" role="alert">Podany e-mail już istnieje.</div>';
                }
            }
            else 
            {
                return '<div class="alert alert-danger" role="alert">Podany użytkownik już istnieje.</div>';
            }
        }catch( PDOException $e ) {
            return $e->getMessage();
        }
 }
 }
类用户{
public$username=null;
public$password=null;
public$useremail=null;
public$steam_id=null;
public$salt=“Zo4rU5Z1YyKJAASY0PT6EUg7BBYdlEhPaNLuxAwU8lqu1ElzHv0Ri7EM6irpx5w”;
公共函数构造($data=array()){
if(isset($data['username'))$this->username=stripslashes(strip_标签($data['username'));
if(isset($data['password'])$this->password=stripslashes(strip_标签($data['password']);
if(isset($data['useremail'])$this->useremail=stripslashes(strip_标记($data['useremail']));
if(isset($data['steam\u id'))$this->steam\u id=stripslashes(strip\u标签($data['steam\u id'));
}
公共函数storeFormValues($params){
//存储参数
$this->\u构造($params);
}
公共职能登记册(){
$correct=false;
试一试{
$con=新的PDO(DB_DSN、DB_用户名、DB_密码);
$con->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_异常);
$sql1=“从user_name=:username LIMIT 1”的用户中选择*;
$polacz1=$con->prepare($sql1);
$polacz1->bindValue(“用户名”,$this->username,PDO::PARAM_STR);
$polacz1->execute();
$row=$polacz1->fetch();
$sql2=“从用户中选择*,其中用户\u email=:useremail LIMIT 1”;
$polacz2=$con->prepare($sql2);
$polacz2->bindValue(“useremail”,$this->useremail,PDO::PARAM_STR);
$polacz2->execute();
$row1=$polacz2->fetch();
$sql3=“从用户中选择*,其中steam\U id=:steam\U id限制1”;
$polacz3=$con->prepare($sql2);
$polacz3->bindValue(“steam_id”,$this->steam_id,PDO::PARAM_STR);
$polacz3->execute();
$row2=$polacz3->fetch();
如果($row==NULL){
如果($row1==NULL){
如果($row1==NULL){
$checksum=bin2hex(mcrypt_create_iv(22,mcrypt_DEV_uradom));
$sql=“插入用户(用户名、用户电子邮件、用户通行证、steam\U id、电子邮件\U哈希)值(:username、:useremail、:password、:steamid、:emailhash)”;
$polacz=$con->prepare($sql);
$polacz->bindValue(“:username”,$this->username,PDO::PARAM_STR);
$polacz->bindValue(“:useremail”,$this->useremail,PDO::PARAM_STR);
$polacz->bindValue(“:password”,散列(“sha256”,“$this->password.$this->salt),PDO::PARAM_STR);
$polacz->bindValue(“:steamid”,$this->steam\u id,PDO::PARAM\u STR);
$polacz->bindValue(“:emailhash“,$checksum,PDO::PARAM_STR);
$polacz->execute();
返回“Zostałeśpomyślnie zarejestowany.Sprawdźpodany addres email i aktywuj swoje konto!”;
//返回“Rejestracja przebiegła pomyślnie,możesz sięzalogować”;
}否则返回“Podany steam ID jużistnieje”;
}
其他的
{
返回“Podany e-mail jużistnieje”;
}
}
其他的
{
返回“Podany użytkownik jużistnieje”;
}
}捕获(PDO$e){
返回$e->getMessage();
}
}
}

投票以打字错误结束:
$polacz3=$con->prepare($sql2)应该是
$polacz3=$con->prepare($sql3),您只是准备了错误的查询文本。哦,天哪。。。谢谢我没说要检查这个。它正在工作!:)投票结束时输入错误:
$polacz3=$con->prepare($sql2)应该是
$polacz3=$con->prepare($sql3),您只是准备了错误的查询文本。哦,天哪。。。谢谢我没说要检查这个。它正在工作!:)