I am using AJAX to call the below method on my register page to validate the form, I have copied in the lines where I am experiencing trouble. I get this message Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in /home/waexchan/public_html/signup.php on line 15 but on the website the message Username is OK is shown so I am confused. Line 15 is the line beginning with $uname_check
?><?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();
}
}
Your sql query seems wrong. Change your query accordingly:
Eg.
$sql = "SELECT username from User WHERE username='$username' LIMIT 1";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.