<?php
$con = mysqli_connect('localhost','root','[mypassword]','dbhwsource');
if(isset($_GET['username'])){
$username = $con->real_escape_string($_GET['username']);
$test = $con->query("SELECT username FROM users WHERE username='$username'");
if($test!=false) die("usererror");
}
if(isset($_GET['email'])){
$email = $con->real_escape_string($_GET['email']);
$test = $con->query("select * from users where email='$email'");
if($test!=false) die("emailerror");
}
$con->close();
echo "ok";
?>
所以我只是想检查用户名/电子邮件是否可用,但无论输入用户名是什么,我得到的都是“usererror”!我很沮丧,到处搜索示例代码,代码看起来没有任何问题。我究竟做错了什么?
编辑:
$test = $test->fetch_assoc();
if(!empty($test)) die("usererror");
这行得通!