0
我正在使用AJAX調用我的註冊頁面上的下面的方法來驗證窗體,我複製了行我遇到麻煩。我收到此消息 警告:mysqli_num_rows()期望參數1爲mysqli_result,布爾在第15行給出的/home/waexchan/public_html/signup.php中給出,但在網站上顯示消息用戶名是OK,所以我很困惑。 15號線是$ uname_check我收到mysqli錯誤消息,但它仍然返回消息
?><?php
if(isset($_POST["usernamecheck"])){
include_once("db_conx.php");
$username = preg_replace('#[^a-z0-9]#i', '', $_POST['usernamecheck']);
$sql = "SELECT username from User WHERE username'$username' LIMIT 1";
$query = mysqli_query($db_conx, $sql);
$uname_check = mysqli_num_rows($query);
if (strlen($username) < 3 || strlen($username) > 16) {
echo '<strong style="color:#F00;">3 - 16 characters please</strong>';
exit();
}
if (is_numeric($username[0])) {
echo '<strong style="color:#F00;">Usernames must begin with a letter</strong>';
exit();
}
if ($uname_check < 1) {
echo '<strong style="color:#009900;">' . $username . ' is OK</strong>';
exit();
} else {
echo '<strong style="color:#F00;">' . $username . ' is taken</strong>';
exit();
}
}