Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.3k views
in Technique[技术] by (71.8m points)

php - Warning: mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement in C:User.. on 148

Hello i'm inserting a new column collegename, branch, and gender but suddenly it's giving me this error...

Warning: mysqli_stmt::bind_param(): Number of variables doesn't match number of 
parameters in prepared statement in C:UsersRajPhpstormProjectsusercakemodels
class.newuser.php on line 148

What's that mean?

actually i was inserting a new column into my database college, branch, year, and gender everything goes well but when i register myself it's shows the message your Registration is successfully submitted but suddenly it shows this error message as wells as?? so where i'm supposed to be wrong please help?

here is my source code:

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

?>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You have 10 ? in your prepare statement but you passed 6 variables to it on $stmt->bind_param. You must pass exactly same variables as you have in statement. Your bind must be something like this:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...