我正在制作一个网页。它的用户形式基本上。我正在使用用户名,密码和电子邮件ID来检查它们是否已存在于数据库中
如果它们存在,我想转到显示“用户名已存在”的下一页,以防用户名在数据库中为dere,或者如果电子邮件ID匹配则显示“您已拥有此ID的帐户”。
这一行后面会有表格。那么请你帮我怎么做?
这是我的代码
<?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 />";
}
?>