This is the code to create a user on my website... I need a while loop for my profile img so I used part of this video code https://youtu.be/I4JYwRIjX6c but when I went to try it it gave me this error:
Fatal error: Uncaught TypeError: mysqli_fetch_assoc(): Argument #1 ($result) must be of type mysqli_result, bool given in C:\xampp\htdocs\WravyBike\Includes\functions.inc.php:152 Stack trace: #0 C:\xampp\htdocs\WravyBike\Includes\functions.inc.php(152): mysqli_fetch_assoc(false) #1 C:\xampp\htdocs\WravyBike\Includes\signup.inc.php(60): createUser(Object(mysqli), 'test', 'test@gma...', '', 'test12') #2 {main} thrown in C:\xampp\htdocs\WravyBike\Includes\functions.inc.php on line 152
here is my code: i'm having a problem with the: while ($row = mysqli_fetch_assoc($result)) & $result = mysqli_stmt_get_result($stmt);
$sql = "INSERT INTO users (usersName, usersEmail, usersTel, usersPwd) VALUES (?, ?, ?, ?);";
// $sql = "INSERT INTO users (usersName, usersEmail, usersTel, usersPwd) VALUES ('$name', '$email', '$tel', '$pwd');";
$stmt = mysqli_stmt_init($conn);
// mysqli_query($conn, $sql);
if (!mysqli_stmt_prepare($stmt, $sql)) {
header("location: ../signup.php?error=stmtfailed");
exit();
}
else{
$pwdHashed = password_hash($pwd, PASSWORD_DEFAULT);
mysqli_stmt_bind_param($stmt, "ssss", $name, $email, $tel, $pwdHashed);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
while ($row = mysqli_fetch_assoc($result)) {
$userid = $row["usersId"];
$sql = "INSERT INTO profileimg (usersId, status) VALUES ('$userid', 1);";
$result = mysqli_query($conn, $sql);
header("Location: ../EditAccount.php");
}
mysqli_stmt_close($stmt);
header("location: ../signup.php?error=none");
exit();
}
$result = mysqli_stmt_get_result($stmt);
At this part, $result will have a bool value (true) If it successfully inserts record (false) if it fails.
If you want to update userstatus in this 'profileimg' table, use this code
$last_id = $conn->insert_id;
mysqli_stmt_bind_param($stmt, "ssss", $name, $email, $tel, $pwdHashed);
if (mysqli_stmt_execute($stmt)) {
$last_id = $conn->insert_id;
$sql = "INSERT INTO profileimg (usersId, status) VALUES ('$last_id', 1);";
$result = mysqli_query($conn, $sql);
header("Location: ../EditAccount.php");
}
``
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.