ここに私のコードです。すべてが完璧に動作します。ユーザー名の重複を防ぎます。私が抱えている唯一の問題は、すでに登録されているユーザーが再度登録しようとすると、「User already exists」と表示されることです。エコーユーザーは既に存在します
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Registration</title>
<link rel="stylesheet" href="style2.css" />
</head>
<body>
<?php
$con = mysqli_connect("localhost","root","","register");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if (isset($_REQUEST['username'])){
$username = stripslashes($_REQUEST['username']);
$username = mysqli_real_escape_string($con,$username);
$password = stripslashes($_REQUEST['password']);
$password = mysqli_real_escape_string($con,$password);
$query = "INSERT into `users` (username, password)
VALUES ('$username', '".md5($password)."')";
$result = mysqli_query($con,$query);
if($result){
echo "<div class='form'>
<h3>You are registered successfully.</h3>
<br/>Click here to <a href='login.php'>Login</a></div>";
}
}else{
?>
<div class="form">
<h1>Registration</h1>
<form name="registration" action="" method="post">
<input type="text" name="username" placeholder="Username" required />
<input type="password" name="password" placeholder="Password" required />
<input type="submit" name="submit" value="Register" />
</form>
</div>
<?php } ?>
</body>
</html>
は、私は、彼らがすでに – nogad
他の問題を存在する場合任意のコードが確認を参照してくださいいけません。 – nogad
したがって、ユーザーが同じユーザー名で登録しようとすると、ユーザー名が既に存在するかどうかを確認する必要がありますか? – Mario