Can someone please explain to me why the code that I have not commented out here is still inserting into my Data base, even when I leave the Sign Up forms input values blank?
Thanks!
PHP
<?php
require_once("connection.php");
if ($_POST['submit'] == "Sign Up") {
if (!$_POST['email']) { $error.="<br />Please enter your email";
} else if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) { $error.="<br />Please enter a valid email address";
} if (!$_POST['password']) { $error.="<br />Please enter your password";
} else if (strlen($_POST['password']) <8) { $error.="<br />Please enter a password of at least 8 characters in length";
} if (!preg_match('`[A-Z]`', $_POST['password'])) { $error.="<br />Please enter at least one Uppder Case charater";
}
if ($error) { echo "There were error(s) in your signup details:".$error;
} else {
$query = "SELECT * FROM `users` WHERE `email`='".mysqli_real_escape_string($link, $_POST['email'])."'";
$result = mysqli_query($link, $query);
$results = mysqli_num_rows($result);
} if ($results) { echo "That email address is already in registered. Do you want to log in?";
} else {
$query = "INSERT INTO `users` (`email`, `password`) VALUES ('".mysqli_real_escape_string($link, $_POST['email'])."', '".md5(md5($_POST['email']).$_POST['password'])."')";
mysqli_query($link, $query);
echo "You've been signed up!";
}
}
//if ($_POST['submit'] == "Log In") {
//$query = "SELECT * FROM `users` WHERE `email` = '".mysqli_real_escape_string($link, $_POST['loginemail'])."' AND `password` = '".md5(md5($_POST['loginemail']).$_POST['loginpassword'])."' LIMIT 1";
//$result = mysqli_query($link, $query);
//$row = mysqli_fetch_array($result);
//} if ($row) {
//$_SESSION['id']=$row['id'];
//print_r($_SESSION);
//} else {
//echo "We could not find a user with that email and password. Please try again.";
//}
?>
HTML
<form method="post">
<input type="email" name="email" id="email" placeholder="Your Email" value="<?php echo addslashes($_POST['email']);?>" />
<input type="password" name="password" id="password" placeholder="Your Password" value="<?php echo addslashes($_POST['email']);?>" />
<input type="submit" name="submit" value="Sign Up" />
</form>
<form method="post">
<input type="email" name="loginemail" id="loginemail" placeholder="Your Email" value="<?php echo addslashes($_POST['loginemail']);?>" />
<input type="password" name="loginpassword" id="loginpassword" placeholder="Your Password" value="<?php echo addslashes($_POST['loginemail']);?>" />
<input type="submit" name="submit" value="Log In" />
</form>