Tuesday, January 1, 2019

php - mysqli_stmt_close() expects to be parameter 1

I've been coding in PHP and connecting it up to MySql. I keep on getting an error




Warning: mysqli_stmt_close() expects parameter 1 to be mysqli_stmt, boolean given in C:\xampp\htdocs\xxxx on line 175




Is there anything wrong with this block of code?



 if(empty(trim($_POST['dept'])) && empty(trim($_POST['fname'])) && empty(trim($_POST['lname'])) && empty(trim($_POST['email'])) && empty(trim($_POST['cnum'])) && empty(trim($_POST['dob'])) && empty(trim($_POST['gender'])) && empty(trim($_POST['minitial'])) && strlen(trim($_POST['minitial'])) > 1   ){
$regerr = "Please complete your information";

}else{
$fname = trim($_POST['fname']);
$lname = trim($_POST['lname']);
$email = trim($_POST['email']);
$cnum = trim($_POST['cnum']);
$dob = trim($_POST['dob']);
$gender = trim($_POST['gender']);
$dept = trim($_POST['dept']);
$minitial = trim($_POST['minitial']);
}


// Check input errors before inserting in database
if(empty($usernameerr) && empty($passworderr) && empty($confirmpassworderr) && empty($regerr) ){

// Prepare an insert statement
$sql = "INSERT INTO login_info (username, password) VALUES (?, ?);
INSERT INTO user_info (fname, sname, minitial, contact_num, gender, dob, department) VALUES (?,?,?,?,?,CAST (? AS DATE),?);";

if($stmt = mysqli_prepare($link, $sql)){
// Bind variables to the prepared statement as parameters

mysqli_stmt_bind_param($stmt, "sssssssss", $param_username, $param_password, $param_fname, $param_sname, $param_minitial, $param_cnum, $param_gender, $param_dob, $param_department);

// Set parameters
$param_username = $username;
$param_password = password_hash($password, PASSWORD_DEFAULT); // Creates a password hash
$param_fname = $fname;
$param_sname = $lname;
$param_minitial =$minitial;
$param_cnum = $cnum;
$param_gender = $gender;

$param_dob = $dob;
$param_department = $dept;

// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt)){

session_start();
$_SESSION['username'] = $username;
$_SESSION['usernumber'] = $mysqli_insert_id($link);
header("location: home-trabawho.php");

} else{
echo "Something went wrong. Please try again later.";
}
}

// Close statement
mysqli_stmt_close($stmt);
}

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...