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

时间:2016-04-24 06:42:53

标签: php mysql pdo

我知道这个错误意味着什么,但我不知道它出现的原因。我检查了变量的名称,PDO变量的名称,数据库中表的名称,但仍然没有。

如果我将插入复制到phpMyAdmin,它运行完美。如果我从$ this->更改所有变量到#abcd'它给了我同样的错误。

我真的不知道它到底发生了什么......

错误:

  

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();
        }
 }
 }

0 个答案:

没有答案