This the the code for my website. It is designed to register new users, only a logged in admin can do this. The account is created successfully, but it doesn’t seem to be returning a 1 for mysqli_num_rows. I printed the value that num_rows returning and nothing came out, not even a 0. I have worked on this for days, I am very new to coding in php so this is probably a glaring mistake, but I can’t see it. Any help would be greatly appreciated. I have search Google, but couldn’t find anything.
if($_SERVER['REQUEST_METHOD']=="POST"){
$name = mysqli_real_escape_string($_POST['fname']);
$email = mysqli_real_escape_string($_POST['email']);
$user = mysqli_real_escape_string($_POST['user']);
$pass = mysqli_real_escape_string(md5($_POST['password']));
$authority = mysqli_real_escape_string($_POST['use']);
$queryCheck = "SELECT `user` FROM `user` WHERE `user`='$user';";
$resultCheck = mysqli_query($link, $queryCheck);
$rowCheck = mysqli_num_rows($resultCheck);
if($rowCheck != 1){
$query = "INSERT INTO `user` (`id`, `name`, `email`,`user`,`pass`) VALUES ($authority,'$name','$email','$user','$pass');";
//echo $query;
$result = mysqli_query($link, $query);
$row = mysqli_affected_rows($result);
if($row == 1){
echo "User Created Successfully!<br/>";
echo '<br/><br/><br/><a href="admin.php">Return to Administration Page</a>';
}else{
echo "User was not created, Please try again.";
}
}else{
echo 'User already exists.';
}
}
I found that you have to use mysqli_affected_rows for an insert phrase in mysql.