1
On my records page I want to check the names of users and emails separately but at the same time.
I could leave the message like this: Username or email already exists
to facilitate but I have never seen a registration page that worked that way.
Additional details:
- I’m using the codes correctly, for each of the
else
has aif
in the code. - In the database there is a table
users
and within the table hasusername
andemail
The
stmt
are working separately.$username = $_POST['username']; $email = $_POST['email']; $id = ''; else{ $stmt = $mysqli -> prepare('SELECT id FROM users WHERE username = ?'); $stmt -> bind_param("s", $username); $stmt -> execute(); $stmt -> bind_result($id); $stmt -> fetch(); if($id > 0){ $user_error = 'Username already exists'; } } else{ $stmt = $mysqli -> prepare('SELECT id FROM users WHERE email = ?'); $stmt -> bind_param("s", $email); $stmt -> execute(); $stmt -> bind_result($id); $stmt -> fetch(); if($id > 0){ $email_error = 'Email already exists'; } }
pq the two queries, one with only one
or
would not solve?– rray
as a matter of convenience for the user to know if the email or username are already in use or both(which in the case of
bind_param
of Fatal error). Nomysqli -> query
this could be done easily. If it is not possible I will have to usemysqli -> query
again to check andbind_param
to enter the data in the database.– Lukaz11