I need your kind help please for validating email ids existed in database and it should not accept like abc, or 123, email id should be proper like abc@gmail.com , means atleast with @ and .com etc.
I would suggest that a better way to handle it would be to set the “email” column as unique in your database table, insert the new address (once you’ve checked that it meets the correct format) and then handle the “duplicate” error from the database if it already exists.
By running a query to see if it exists, then a separate query to insert it, you’re allowing a situation called (I think) a “race condition”, where two users can sign up at virtually the same time with the same email address, because you have no control over how the server schedules the two processes, or even if the two processes run on the same server. It’s entirely possible that the first “check” query will run and not find the email address, then the check-query for the second user will run and get the same results, then the two inserts will run, and you end up with duplicates.
Let the database do the work, it can handle it.
if ($count>=1) {
Why would you allow more than one row in the database to have the same email address?
error_reporting(0);
While you’re developing the code, I’d suggest this is the wrong setting. You should consider perhaps using
error_reporting(E_ALL);
As for validating the email to make sure it’s valid, what have you tried? There’s a function called filter_var() that will do basic checks.
You also need to read up on Prepared Statements rather than concatenating variables directly into queries as you do.
Finally, in the nicest possible way, don’t put code on here as screen-shots. If someone wants to try your code out to try to help you with a problem, they can’t copy-paste from a screen-shot into a code editor.
That was one of the top results when I searched for “php validate email address”. There may be better ways to do it now, I’m sure someone will point them out.
That change in itself was just to stop PHP suppressing error messages - while you’re developing your code, you want to see all error messages, not hide them away. It won’t have made any difference to whether your code accepts invalid email addresses - you’ll have to write that bit yourself. Again, the error_reporting() function is fully documented so you can see what it was intended to do.