Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 警告:mysqli_stmt::bind_param():变量数量与148上C:\User..\n中准备语句中的参数数量不匹配_Php_Mysql_Mysqli_Prepared Statement - Fatal编程技术网

Php 警告:mysqli_stmt::bind_param():变量数量与148上C:\User..\n中准备语句中的参数数量不匹配

Php 警告:mysqli_stmt::bind_param():变量数量与148上C:\User..\n中准备语句中的参数数量不匹配,php,mysql,mysqli,prepared-statement,Php,Mysql,Mysqli,Prepared Statement,我正在插入一个新的专栏collegename,branch,andgender,但突然它给了我这个错误 Warning: mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement in C:\Users\Raj\PhpstormProjects\usercake\models \class.newuser.php on line 148 那是什

我正在插入一个新的专栏collegename,branch,andgender,但突然它给了我这个错误

Warning: mysqli_stmt::bind_param(): Number of variables doesn't match number of 
parameters in prepared statement in C:\Users\Raj\PhpstormProjects\usercake\models
\class.newuser.php on line 148
那是什么意思

事实上,我在我的数据库中插入了一个新的专栏——学院、分校、年份和性别——一切都进行得很顺利,但当我注册自己时,它显示了一条消息:你的注册成功提交了,但突然它也显示了这条错误消息

以下是我的源代码:

<?php
class User 
{
    public $user_active = 0;
    private $clean_email;
    public $status = false;
    private $clean_password;
    private $username;
    private $displayname;
    public $sql_failure = false;
    public $mail_failure = false;
    public $email_taken = false;
    public $username_taken = false;
    public $displayname_taken = false;
    public $activation_token = 0;
    public $success = NULL;
    
    function __construct($user,$display,$pass,$email)
    {
        //Used for display only
        $this->displayname = $display;
        
        //Sanitize
        $this->clean_email = sanitize($email);
        $this->clean_password = trim($pass);
        $this->username = sanitize($user);
        
        if(usernameExists($this->username))
        {
            $this->username_taken = true;
        }
        else if(displayNameExists($this->displayname))
        {
            $this->displayname_taken = true;
        }
        else if(emailExists($this->clean_email))
        {
            $this->email_taken = true;
        }
        else
        {
            //No problems have been found.
            $this->status = true;
        }
    }
    
    public function userCakeAddUser()
    {
        global $mysqli,$emailActivation,$websiteUrl,$db_table_prefix;
        
        //Prevent this function being called if there were construction errors
        if($this->status)
        {
            //Construct a secure hash for the plain text password
            $secure_pass = generateHash($this->clean_password);
            
            //Construct a unique activation token
            $this->activation_token = generateActivationToken();
            
            //Do we need to send out an activation email?
            if($emailActivation == "true")
            {
                //User must activate their account first
                $this->user_active = 0;
                
                $mail = new userCakeMail();
                
                //Build the activation message
                $activation_message = lang("ACCOUNT_ACTIVATION_MESSAGE",array($websiteUrl,$this->activation_token));
                
                //Define more if you want to build larger structures
                $hooks = array(
                    "searchStrs" => array("#ACTIVATION-MESSAGE","#ACTIVATION-KEY","#USERNAME#"),
                    "subjectStrs" => array($activation_message,$this->activation_token,$this->displayname)
                    );
                
                /* Build the template - Optional, you can just use the sendMail function 
                Instead to pass a message. */
                
                if(!$mail->newTemplateMsg("new-registration.txt",$hooks))
                {
                    $this->mail_failure = true;
                }
                else
                {
                    //Send the mail. Specify users email here and subject. 
                    //SendMail can have a third parementer for message if you do not wish to build a template.
                    
                    if(!$mail->sendMail($this->clean_email,"New User"))
                    {
                        $this->mail_failure = true;
                    }
                }
                $this->success = lang("ACCOUNT_REGISTRATION_COMPLETE_TYPE2");
            }
            else
            {
                //Instant account activation
                $this->user_active = 1;
                $this->success = lang("ACCOUNT_REGISTRATION_COMPLETE_TYPE1");
            }   
            
            
            if(!$this->mail_failure)
            {
                //Insert the user into the database providing no errors have been found.
                $stmt = $mysqli->prepare("INSERT INTO ".$db_table_prefix."users (
                    user_name,
                    display_name,
                    password,
                    email,
                    college,
                    branch,
                    year,
                    gender,
                    activation_token,
                    last_activation_request,
                    lost_password_request, 
                    active,
                    title,
                    sign_up_stamp,
                    last_sign_in_stamp
                    )
                    VALUES (
                    ?,
                    ?,
                    ?,
                    ?,
                    ?,
                    ?,
                    ?,
                    ?,
                    ?,
                    '".time()."',
                    '0',
                    ?,
                    'New Member',
                    '".time()."',
                    '0'
                    )");
                
                $stmt->bind_param("sssssi", $this->username, $this->displayname, $secure_pass, $this->clean_email, $this->activation_token, $this->user_active);
                $stmt->execute();
                $inserted_id = $mysqli->insert_id;
                $stmt->close();
                
                //Insert default permission into matches table
                $stmt = $mysqli->prepare("INSERT INTO ".$db_table_prefix."user_permission_matches  (
                    user_id,
                    permission_id
                    )
                    VALUES (
                    ?,
                    '1'
                    )");
                $stmt->bind_param("s", $inserted_id);
                $stmt->execute();
                $stmt->close();
            }
        }
    }
}

?>

你有10个?在prepare语句中,但在$stmt->bind_param上向它传递了6个变量。您必须传递和语句中完全相同的变量。您的绑定必须如下所示:

$stmt->bind_param('isisississ', $int1, $str1, $int2, $str2, $int3, $str3, $str4, $int4, $str5, $str6);

你最近不是问了同样的问题吗?你有更多的问题吗?它的意思就是:您的查询与您提供的参数不匹配。您只提供了6个参数,但占位符要多得多?我给您的是-1。理由:这样的信息很容易理解。我这么说是因为我是凭经验说话的——几年前我也有同样的错误信息,我能够自己解决它,而不用去网站,也不用花时间问问题。它告诉您变量的数量与语句中参数的数量不匹配。在那一点上,你唯一要做的事情是什么?为什么要去计算你在那一行绑定和执行的参数和变量的数量?这纯粹是懒惰,如果你不花时间调试,那有什么意义呢?你有10个?但是SSS I不是10个字符。。。。