I am making a webpage. Its user's form basically. I am taking username, password n email ID n checking if they already exist in the database or not.
If they exist i want to move to a next page showing 'username already exists' in case username is dere in DB or it will show 'You already have account on this id' in case email id matches.
this line will be followed by form. So can you please help me how to do it?
here's my code
<?php
$host = "localhost";
$user = "root";
$password = "";
$database = "signin";
$table = "userdetails";
$userName = $_POST['userName'];
$emailId = $_POST['emailID'];
$password = $_POST['password'];
$cnfPassword = $_POST['cnfPassword'];
$con = mysql_connect($host, $user) or die(mysql_error());
mysql_select_db($database, $con) or die(mysql_error());
if ($password == $cnfPassword && strlen($password) != 0) {
echo "Your Password Matched\n";
echo "<br />";
} else {
echo "Please enter a valid password \n";
echo "<br />";
}
$result = mysql_query("SELECT * FROM `userdetails` WHERE `UserName`=\"$userName\"");
$count = 0;
while ($row = mysql_fetch_array($result)) {
$count++;
echo "UserID ".$row['UserID']."<br />UserName: ".$row['UserName']."<br />EmailID: ".$row['emailID']."\n";
}
if ($count == 0 && $password == $cnfPassword && strlen($password) != 0) {
$query = "INSERT INTO userdetails (UserName,emailID,Password) VALUES('$userName','$emailId','$password')";
$result = mysql_query($query);
echo $result;
echo "<br />";
echo "You ar welcomed\n";
echo "<br />";
} else {
action("sign_up.php");
echo "<br />Username already exists\n";
echo "<br />";
}
?>