Get this error. Not really sure why. Code is below - using prepared statements for SQL in PHP.
Fatal error: Uncaught Error: mysqli_stmt object is not fully initialized in C:\xampp\htdocs\includes\register.inc.php:35
<?php
if (isset($_POST["reg_submit"])) {
$fName = $_POST["fName"];
$lName = $_POST["lName"];
$authority = $_POST["authority"];
$email = $_POST["email"];
$phone = $_POST["phone"];
$pwd = $_POST["pwd"];
$pwdConfirm = $_POST["pwdConfirm"];
$invite_code = $_POST["invite_code"];
require_once "dbh.inc.php";
if (empty($email) || empty($phone) || empty($pwd) || empty($pwdConfirm) || empty($invite_code)) {
header("Location: ../register.php?invite=".$invite_code."&error=emptyfields");
exit();
}
if ($pwd !== $pwdConfirm) {
header("Location: ../register.php?invite=".$invite_code."&error=pwdnomatch");
exit();
}
if (!preg_match('/[\'\/~`\!@#\$%\^&\*\(\)_\-\+=\{\}\[\]\|;:"\<\>,\.\?\\\]/', $pwd)) {
header("Location: ../register.php?invite=".$invite_code."&error=pwdcomplexity");
exit();
}
if (strlen($pwd) < 12) {
header("Location: ../register.php?invite=".$invite_code."&error=pwdcomplexity");
exit();
}
$sql = "SELECT * FROM administrators WHERE admin_email = ?;";
$stmt = mysqli_stmt_init($conn);
mysqli_stmt_prepare($stmt, $sql);
mysqli_stmt_bind_param($stmt, "s", $email);
mysqli_stmt_execute($stmt);
$resultData = mysqli_stmt_get_result($stmt);
$num = mysqli_num_rows($resultData);
if ($num !== 0) {
header("Location: ../register.php?invite=".$invite_code."&error=emailinuse");
exit();
}
dbh.inc.php
<?php
$serverName = "localhost";
$serverUsername = "root";
$serverPwd = "";
$serverDb = "scholar23";
$conn = mysqli_connect($serverName, $serverUsername, $serverPwd, $serverDb); if (!$conn) {
echo "Error connecting to the server.";
exit();
}
Tried nothing as can't think of what the problem is. Any help appreciated.