我正在制作一个网页。其用户形式基本。我正在使用用户名、密码 n 电子邮件 ID n 检查它们是否已经存在于数据库中。
如果它们存在,我想移动到显示“用户名已经存在”的下一页,以防用户名在 DB 中,或者如果电子邮件 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 />";
}
?>