我正在用 PHP 编写条件来检查是否使用了某些用户凭据,并且正在使用if....elseif....else
条件方法来执行此操作。在每个语句中,如果该语句为真,我将定义一个变量的值。无论如何,该else
值始终被使用。
另外,如果你想要布朗尼点,这会更容易做一个switch
声明吗?
$username = $_POST['username'];
$password = strong_crypt($_POST['password'] . $username );
$name = $_POST['name'];
$email = $_POST['email'];
while($row = mysqli_fetch_array($query))
{
$allEmails = $row['email'];
$allUnames = $row['uname'];
}
if($allEmails === $email)
{
$message = "That email already exists. You can only have one account per email address.";
}
elseif($allUnames === $username)
{
$message = "That username has already been taken. Please choose a different one.";
}
elseif($username === null || $email === null || $password === null || $name === null)
{
$message = "Please fill out all fields to register";
}
else
{
mysqli_query($conn, "INSERT INTO login (name, uname, pword, email, lat, lon, it) VALUES ('$name', '$username', '$password', '$email', '$lat', '$lon', '$it')");
$message = "goodtogo";
}