我想我只是错过了这个问题......
如果我运行此代码,如果用户名已经等于用户输入的用户名,则应显示“用户名已存在”。
但到目前为止,它只显示“已成功注册”,“请再试一次!”或者“请填写所有值”,但它从未显示“用户名已存在”..我在这里有什么错误?
<?php
$username = $_GET['username'];
$password = $_GET['password'];
if($username == '' || $password == ''){
echo 'please fill all values';
}
else{
require_once('dbConnect.php');
$sql = "SELECT * FROM HL WHERE username='$username'";
$check = mysqli_fetch_array(mysqli_query($con,$sql));
if(isset($check)){
echo 'username already exists';
}
else{
$sql = "INSERT INTO HL(username,password) VALUES('$username','$password')";
if(mysqli_query($con,$sql)){
echo 'successfully registered';
}else{
echo 'Please try again!';
}
}
mysqli_close($con);
}
答案 0 :(得分:0)
希望这有帮助
$check = mysqli_fetch_array(mysqli_query($con,$sql));
if($check){
echo 'username already exists';
}
从该条件中删除isset