How to check correct email address for user registration in PHP?

Sultan

New member
I'm making a member base website.
For user registration, I've made a scrip. Code is here.

<?php

$submit = (isset($_POST['submit'])) ? $_POST['submit'] : '';

$firstname = strip_tags((isset($_POST['firstname'])) ? $_POST['firstname'] : '');
$lastname = strip_tags((isset($_POST['lastname'])) ? $_POST['lastname'] : '');
$email = strtolower(strip_tags((isset($_POST['email'])) ? $_POST['email'] : ''));
$password = strip_tags((isset($_POST['password'])) ? $_POST['password'] : '');
$repeatpassword = strip_tags((isset($_POST['repeatpassword'])) ? $_POST['repeatpassword'] : '');
$sex = strip_tags((isset($_POST['sex'])) ? $_POST['sex'] : 'M');
$dob = strip_tags((isset($_POST['birthmonth'])) ? $_POST['birthmonth'] : '1') . "/" . strip_tags((isset($_POST['birthday'])) ? $_POST['birthday'] : '1') . "/" . strip_tags((isset($_POST['birthyear'])) ? $_POST['birthyear'] : '1900');

$birthmonth = strip_tags((isset($_POST['birthmonth'])) ? $_POST['birthmonth'] : '');
$birthday = strip_tags((isset($_POST['birthday'])) ? $_POST['birthday'] : '');
$birthyear = strip_tags((isset($_POST['birthyear'])) ? $_POST['birthyear'] : '');

if ($birthyear != '' && $birthmonth != '' && $birthday != '') {
// Generate date of birth in format of YYYY-mm-dd
$dob = $birthyear.'-'.$birthmonth.'-'.$birthday;
}
$date = date("Y-m-d");

if ($submit)
{
$connect = mysql_connect("localhost","root","");
mysql_select_db("phplogin");

$emailcheck = mysql_query("SELECT email FROM users WHERE email='$email'");
$count = mysql_num_rows($emailcheck);

if ($count!=0)
{
die ("<html><form class='warn'><tr><td><p>This email is already registered.</p></td></tr></form><html>");
}


if ($firstname&&$lastname&&$email&&$password&&$repeatpassword&&$sex&&$dob)
{

if ($password==$repeatpassword)
{
if (strlen($firstname)>25||strlen($lastname)>25)
{
echo "<html><form class='warn'><tr><td><p>Length of Firstname/Lastname is too long!</p></td></tr></form><html>";
}
else
{
if ((strstr($email, "@")) && (strstr($email, "."))){

}
die ("Please enter a valid Email address.");
if (strlen($password)>25||strlen($password)<6)
{
echo "<html><form class='warn'><tr><td><p>Password must be between 6 to 25 characters.</p></td></tr></form><html>";
}
else
{
//register the user!
$password = md5($password);
$repeatpassword = md5($repeatpassword);

$queryreg = mysql_query("
INSERT INTO users VALUES ('','$firstname','$lastname','$email','$password','$sex','$dob','$date')
");

$id = mysql_insert_id();
$queryreg = mysql_query("INSERT INTO profile SET id = '$id',firstname = '$firstname', lastname = '$lastname', sex = '$sex', email = '$email', dob = '$dob' ");
$queryreg = mysql_query("INSERT INTO images SET id = '$id', email = '$email', imagelocation = 'avatars/pic.jpg' ");



die ("You've been registered! <a href='index.php'>Return to login page.</a>");
}
}
}
else
echo "<html><form class='warn'><tr><td><p>Your passwords do not match</p></td></tr></form><html>";
}
else
echo "<html><form class='warn'><tr><td><p>Please fill in <b>all</b> fields.</p></td></tr></form><html>";
}

?>

Problem is that when user enter even correct email with @ and . symbols, it still ask user to enter correct email.
Can anyone tell me where is the problem and how to fix it ?
 
Back
Top