<?php
if(isset($_POST['submit'])){
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";
}
}
if(!$_POST['password']){
$error.="<br/>please Enter Your Password";
}
else {
if (strlen($_POST['password'])<8){
$error.="<br/>please Enter long Password";
}
if (!preg_match("#[a-z]+#",$_POST['password'])){
$error.="<br/>please Enter strong Password";
}
}
if (isset($error)) {
echo "There Were error(s) In Your Signup Details :" .$error;
}
else {
$link = mysqli_connect("localhost","root","password","test");
$email=$_POST['email'];
$query ="SELECT * FROM users WHERE email ='".mysqli_real_escape_string($link,$email)."'";
$result = mysqli_query($link,$query);
$results = mysqli_num_rows($result);
if($results) echo "Email is already registered ,, Do you want log In ";
else {
$email = $_POST['email'];
// md5(md5($_POST['email']).
$password = $_POST['password'];
$query ="INSERT INTO users ('email','password') VALUES ('".mysqli_real_escape_string($link,$email)."',$password)";
if (mysqli_query($link, $query)) {
echo "You have been succesfully signed up!";
} else {
echo "Something went wrong";
}
}
}
}
?>
<form method="post">
<input type="email" name="email" id="name"/>
<input type="password" name = "password"/>
<input type ="submit" name="submit" value="LogIn"/>
</form>
the mistake in this part in this code because the message show is the user been singed up but his email and password not added to the database
if($results) echo "Email is already registered ,, Do you want log In ";
else {
$email = $_POST['email'];
// md5(md5($_POST['email']).
$password = $_POST['password'];
$query ="INSERT INTO users ('email','password') VALUES ('".mysqli_real_escape_string($link,$email)."',$password)";
if (mysqli_query($link, $query)) {
echo "You have been succesfully signed up!";
} else {
echo "Something went wrong";
}
}
}
}
?>