Background:
I have a form that I use to add information to a database and everything works fine.
I tried to get a users id by his username(filled in the form)
this is the users database:
The Problem:
When I try to get a result from the database I get an error, my $result is apparently not an object type but a bool.
here is my code:
$sql1 = "SELECT idUsers FROM users WHERE uidUsers=?;";
$stmt1 = mysqli_stmt_init($conn);
if(!mysqli_stmt_prepare($stmt1, $sql1)){
header("Location:../add_sale.php?error=sqlerror");
exit();
}
else{
mysqli_stmt_bind_param($stmt1, "s", $name);
$result = mysqli_query($conn, $sql1);
if($result->num_rows === 0){
header("Location:../add_sale.php?error=nouser");
exit();
}
else{
while($row = mysqli_fetch_assoc($result)){
$a = $row["idUsers"];
}
after that I insert all the wanted data and $a
.
the script gets this errors:
Notice:Trying to get property 'num_rows' of non-object in ...
Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, bool given in ...