$result = mysqli_query($con ,“SELECT * FROM users WHERE username=’” . $username . “’ AND email=’” . $email . “’”);
will get (SELECT) all fields (*) from the table “users” if the username column is an exact match to the value held in the $username variable and the email column is an exact match to the value held in the $email variable and it will return all records that match.
In the next lines:
if(mysqli\_num\_rows($result) \> 0) { echo "User exist"; }
You test to see how many records are returned. If it found any, then it outputs the string “User exist”. This I believe is working properly. I used the same name/mail I used earlier and it output “User exist”.
The “else” part of that if statement happens when it doesn’t find any one and that’s where you need to do a query to INSERT the record in the database.
But here is where you might have a problem. And this is likely my error, but it’s because I don’t know your database scheme. I cant see how you have the table defined in MySQL. This is the current command to insert data into the DB:
$sql = "INSERT INTO users (username, pw, email) VALUES(null, '" . $username . "', '" . $pw . "', '" . $email . "')";
Your script is giving an error about a column count not matching. That’s because the first set of parens: (username, pw, email) defines three fields we will be inserting data into. The parans after VALUES is defining four things null, a string with the value from $username a string with the value from $pw and a string with the value from $email. To fix this error remove the null, and that will make the columns match. You likely have an autoincrementing “id” column (the “null”) and you could specify that in the first parens, but since I can’t see that, lets go with what we know will work and take the null, (including the comma) out.
This leads us to our next problem. In the first parens you’re saying your database table has columns named “username”, “pw” and “email”. I would be willing to be that’s wrong and the column names are really “username”, “password” and “email”. If I’m right, you will get another error about an undefined column. Change the pw in the first parens to password if this is the case. Leave the second $pw alone. That’s a variable with your encrypted password in it.
It’s way late here where I am so I won’t be responding again until tomorrow.
Rob