Hello All,

Rookie here...

I have run into a problem coding my first Registration form with PHP. Everything works great with the form. I just want to know how to check two fields in the database to see if the values being posted already exist. I have one working but, how do I enter in the other check if the one thats in there already initiates the rest of the script?

$q = "SELECT uid FROM table WHERE email = '$email'"; // I want to check another field here before it runs the script below but, at the "else" I need it to read two different error messages base on which one comes back or if both came back with a value greater than 0.

$r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br /> MySQL Error: .mysqli_error($dbc));

if (mysqli_num_rows($r) == 0) { // Available
run the rest of my script....
echo 'you entered the an existing email address.'

Any suggestions???

Edited by happygeek: fixed formatting

8 Years
Discussion Span
Last Post by R0bb0b

Although I am not entirely familiar with mysqli query's, I do know that there is a chance of the $email variable being embeded wrong. Below is the script and its replacement.

//Your script:
$q = "SELECT uid FROM table WHERE email = '$email'";

//Above needs to be replaced with below:
$q = "SELECT uid FROM table WHERE email = '".$email."'";

What you need is two variables, one to collect errors(I usually use an array) and the other would be a boolean. The boolean can either be true or false to begin with depending on how you want to go about it. If you start with true then change it to false if any fields do exist and add to the error that occurred to the array. You will do all of this prior to inserting any data in the database. Then you can check the value of your boolean variable to determine if you will proceed processing the form or send an error back to the user.

This article has been dead for over six months. Start a new discussion instead.
Be sure to adhere to our posting rules.