Php tutorial 8 - Php and Mysql,Check if user exist in database,check by email

preview_player
Показать описание
Check if a user is allready register to your website,if yes,don't register again and redirect to login page.
Рекомендации по теме
Комментарии
Автор

really very easy to understand your tutorial because of comments after codes

anikhasan
Автор

iT'S WORK FOR ME
$query = "SELECT User_Email FROM `user_login` WHERE User_Email = '$Email'";
$fire = mysqli_query($conn, $query);
if(mysqli_num_rows($fire) > 0){
echo "User Alrady Taken";
}

fivernoyon
Автор

I put here all the code....

<!DOCTYPE html>
<html>
<head>
<title>Php tutorial - Registration system with html, php and css</title>
<link href="style.css" rel="stylesheet">
<script type="text/javascript">
$(document).ready(function(){

rules:{
name:{
required:true,
minlength:5
},
email:{
required:true,
email:true,
},
password:{
required:true,
minlength:5
},
password2:{
required:true,
equalTo:"#password",
}


},
messages:{
name:{
required:"Name is required",
minlength:"Minim lenght 5 char"
},
email:{
required:"Email is required",
email:"Please enter a valid email"
},
password:{
required:"Password is required",
minlength:"Password to short"
},
password2:{
required:"Re-type password",
equalTo:"Password don't match",
}
},
wrapper:"div class='errors'",
});

});

</script>
</head>
<body>
<div class="container">
<h2>Php tutorial - Registration system with html, php and css and check if user already registered</h2>
<form name="registeruser" action="<?php echo method="post">
<label>Name:</label>
<input class="nice" name="name" type="text" value=""/>
<label>Email:</label>
<input class="nice" name="email" type="text" value=""/>
<label>Password:</label>
<input class="nice" name="password" type="password" id="password" value=""/>
<label>Re-type Password:</label>
<input class="nice" name="password2" type="password" id="password2"value=""/>
<input class="centered" type="submit" name="submit" value="Register"/>
</form>
<?php
if(isset($_POST['submit']))
{
$name=clear($_POST['name']);


//echo $name.' '.$email.' '.$password;
$connection=mysql_connect("localhost", "root", "");
if(!$connection)
die("mysql connection error".mysql_error());
//echo "Connection ok";
//select db

$db=mysql_select_db("user");
if(!$db)
die("Db error".mysql_error());
//echo "database selected ok";
//let's see if user allready exist in database
$check="select * from user_data where email='$email'";
$go=mysql_query($check);
if(mysql_num_rows($go))
{
echo "user exist, please login";
}
else
{
echo "user not found, inser data to database";
$user="INSERT INTO user_data(name, email, password) VALUES ('$name', '$email', '$password')";

if(!$checkagain)
echo "data inserted error";
else
echo "New user added to database";
}
}
function clear($f){

$f=trim($f);
$f=stripslashes($f);
$f=htmlspecialchars($f);
return $f;
}
?>
</div>
</body>
</html>

ivuromania
Автор

count function always returning value 1, even no user name exist.

saikiran-vmpm