[Solved] Help in php / mysql

<?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";
}
		}
	
	}
}

?>

I cleaned up your code.
You need to use triple backticks to post code to the forum.
See this post for details.

1 Like

Echo is reached whether the mysqli_query does anything or not.

If you haven’t fixed it, I will have a look at it when I’m home.

i post the rest of code , see it

Change:

mysqli_query($link,$query);
echo "You been SignUp";

To:

if (mysqli_query($link, $query)) {
    echo "You have been succesfully signed up!";
} else {
    echo "Something went wrong";
}

I suppose that should work.

1 Like

yes something went wrong

Done , Thank you ,

1 Like

Thanks all , The problem solved

Change

$query ="INSERT INTO users ('email','password') VALUES

To

$query = "INSERT INTO users (email,password) VALUES
1 Like