View Full Version : trying to create a email validating checker

07-19-2012, 07:50 PM
as the title says i am tryng to get my fourm to say "please enter a valid email type" when the user puts in something like randomguy2 as their email and forgets @hotmail or @ gmail or what their mail address is.
thanks in advance


//Create a variable we can use to determine if the user input is good or not
$complete = true;

//Check for username
if (empty($_POST['username'])) {
echo 'Username is required';
$complete = false;

//Check for password
if (empty($_POST['password'])) {
echo 'Password is required';
$complete = false;

//Check to see if passwords match
if ($_POST['password'] != $_POST['confirm_password']) {
echo 'Passwords do not match';
$complete = false;

//Check for email
if (empty($_POST['email']))
echo 'Email is required';
$complete = false;
if (filter_var(email, FILTER_VALIDATE_EMAIL !== false)) {
// The email address is valid
} else {
// The email address is not valid
echo "This Is Not A Valid Email!";


//If we have both a name and an email, save the user to the database
if ($complete == true) {
$conn = mysqli_connect('', '', '', '') or die('Could not connect: ' . mysql_error());

//Hash the password before saving it to make the value obscure
$passwordHash = sha1('password');
$sql = "INSERT INTO admins (username, password, email) VALUES ('$_POST[username]', '$passwordHash', '$_POST[email]')";

mysqli_query($conn, $sql);
echo "Admin added";
else {
echo 'Click <a href="javascript:history.go(-1)">HERE</a> to go back and adjust your entry.';