0

I want to add one field "type_login" than I'm getting some error messages PHP script. missing code please help me...

error ->

Warning: mysqli_stmt_bind_param(): Number of elements in type definition string doesn't match number of bind variables in D:\xammp\htdocs\raisebux\admin\member-register.php on line 85

line no. 85

mysqli_stmt_bind_param($stmt, "ss", $param_username, $param_password, $param_type);

table login

insert in a table data this type

user_id | username | password | type_login
     1  | abcd     | xxxxxxxx |        1
     2  | avcd     | xxxxxxxx |        2
     3  | hbcd     | xxxxxxxx |        3

PHP insert script here...

if($_SERVER["REQUEST_METHOD"] == "POST"){

    if(empty(trim($_POST["username"]))){
        $username_err = "Please enter a username.";
    } else{
        $sql = "SELECT user_id FROM  login WHERE username = ?";

        if($stmt = mysqli_prepare($conn, $sql)){
            mysqli_stmt_bind_param($stmt, "s", $param_username);

            $param_username = trim($_POST["username"]);

            if(mysqli_stmt_execute($stmt)){
                mysqli_stmt_store_result($stmt);

                if(mysqli_stmt_num_rows($stmt) == 1){
                    $username_err = "This username is already taken.";
                } else{
                    $username = trim($_POST["username"]);
                }
            } else{
                echo "Oops! Something went wrong. Please try again later.";
            }
        }

        mysqli_stmt_close($stmt);
    }
  //------------------------
  if(empty(trim($_POST["type_login"]))){
        $type_login_err = "Select User Type.";
    } else{
        $sql = "SELECT type_login FROM  login WHERE type_login = ?";

        if($stmt = mysqli_prepare($conn, $sql)){
            mysqli_stmt_bind_param($stmt, "s", $param_type);

            $param_type = trim($_POST["type_login"]);


        }

        mysqli_stmt_close($stmt);
    }



    //------------------------
    if(empty(trim($_POST["password"]))){
        $password_err = "Please enter a password.";     
    } elseif(strlen(trim($_POST["password"])) < 6){
        $password_err = "Password must have atleast 6 characters.";
    } else{
        $password = trim($_POST["password"]);
    }

    if(empty(trim($_POST["confirm_password"]))){
        $confirm_password_err = "Please confirm password.";     
    } else{
        $confirm_password = trim($_POST["confirm_password"]);
        if(empty($password_err) && ($password != $confirm_password)){
            $confirm_password_err = "Password did not match.";
        }
    }



    if(empty($username_err) && empty($password_err) && empty($confirm_password_err) && empty($type_login_err)){

        $sql = "INSERT INTO login (username, password, type_login) VALUES (?, ?, ?)";

        if($stmt = mysqli_prepare($conn, $sql)){
            mysqli_stmt_bind_param($stmt, "ss", $param_username, $param_password, $param_type);

            $param_username = $username;
          $param_type = $type_login;
            $param_password = password_hash($password, PASSWORD_DEFAULT); 

            if(mysqli_stmt_execute($stmt)){
                header("location: sign-in.php");
            } else{
                echo "Something went wrong. Please try again later.";
            }
        }
        mysqli_stmt_close($stmt);
    }
    mysqli_close($conn);
}
?>

html form here

<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">

        <div class="form-group <?php echo (!empty($username_err)) ? 'has-error' : ''; ?>">

            <label>Username</label>

            <input type="text" name="username" class="form-control" value="<?php echo $username; ?>">

            <span class="help-block"><?php echo $username_err; ?></span>

        </div>

        <div class="form-group <?php echo (!empty($password_err)) ? 'has-error' : ''; ?>">

            <label>Password</label>

            <input type="password" name="password" class="form-control" value="<?php echo $password; ?>">

            <span class="help-block"><?php echo $password_err; ?></span>

        </div>

        <div class="form-group <?php echo (!empty($confirm_password_err)) ? 'has-error' : ''; ?>">

            <label>Confirm Password</label>

            <input type="password" name="confirm_password" class="form-control" value="<?php echo $confirm_password; ?>">

            <span class="help-block"><?php echo $confirm_password_err; ?></span>

        </div>

        <div class="form-group<?php echo (!empty($type_login_err)) ? 'has-error' : ''; ?>">

            <label>Select User Type</label>

            <select  name="type_login"  class="form-control"  required>

               <option value="">Select</option>

               <option value="1">SuperAdmin</option>

               <option value="2">Admin</option>

               <option value="3">User</option>

            </select>

           <span class="help-block"><?php echo $type_login_err; ?></span>

     </div>                                                                     
      <div class="form-group">
            <input type="submit" class="btn btn-primary" value="Submit">
            <input type="reset" class="btn btn-default" value="Reset">
      </div>                                    
    </form>

closed as off-topic by MrWhite, John Conde May 22 at 18:28

  • This question does not appear to be about webmastering within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • This question appears to be off-topic because it is about web development which is off-topic at Pro Webmasters. Web development questions may be asked at Stack Overflow but be sure to read their FAQ before posting to ensure your question meets their guidelines. In its current form, this question does not meet their guidelines. – John Conde May 22 at 18:28
1
mysqli_stmt_bind_param($stmt, "ss", $param_username, $param_password, $param_type);

You are only defining 2 bind variable types s and s in the type definition string "ss" (2nd argument), but you are passing 3 bind variables ($param_username, $param_password and $param_type) in the following function arguments, hence the error: "Number of elements in type definition string doesn't match number of bind variables".

You need to pass 3 variable types, corresponding to the 3 bind variables, depending on the data types of those columns. If it's another string then "sss", however, it looks like an integer, so maybe "ssi".

Reference:

Not the answer you're looking for? Browse other questions tagged or ask your own question.