chaseman Posted February 3, 2011 Share Posted February 3, 2011 My code looks as follows: include('connectvars.php'); /* REGISTER FORM */ // check if submit button has been clicked if (isset($_POST['submit_signup'])) { // process and assign variables after post submit button has been clicked $user_email = strip_tags(trim($_POST['email'])); $firstname = strip_tags(trim($_POST['firstname'])); $lastname = strip_tags(trim($_POST['lastname'])); $nickname = strip_tags(trim($_POST['nickname'])); $password = $_POST['password']; $repassword = $_POST['repassword']; $dob = $_POST['dob']; $find_us_question = strip_tags(trim($_POST['find_us_question'])); // connect to database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $check_query = "SELECT * FROM users WHERE nickname = '$nickname'"; $check_connect = mysqli_query($dbc, $check_query); $check_count = mysqli_num_rows($check_connect); echo $check_count; die(); [/code] It's a register (sign up) page, and it's the beginning of the script, the rest of the script is just checking if all fields are a empty and if the input is in the allowed character length etc. I could it off at die(); because the rest doesn't matter. I want the script to check if the username already exists in the database, so I want mysqli_num_rows to tell me how many rows are already there with the same username, and then I want to continue doing an if statement saying [code=php:0] if ($check_count != 0) { echo "Username already exists!" } [/code] But the mysqli_num_rows doesn't even print out how many rows there are availible, it gives me an error saying: Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in... The num_rows function worked in the login script the same way, but for some reason it's not working in the register script. Any ideas, what I'm doing wrong? For testing purposes I just want it to print me "1" when I'm entering a username that's already in the database. Quote Link to comment https://forums.phpfreaks.com/topic/226587-mysqli_num_rows-is-giving-me-an-error/ Share on other sites More sharing options...
PFMaBiSmAd Posted February 3, 2011 Share Posted February 3, 2011 If you do a search on that error message, you will find that it means that your query failed due to an error of some kind. For debugging purposes, use the following error checking on your query - $check_connect = mysqli_query($dbc, $check_query) or die(mysqli_error($dbc)); Quote Link to comment https://forums.phpfreaks.com/topic/226587-mysqli_num_rows-is-giving-me-an-error/#findComment-1169489 Share on other sites More sharing options...
chaseman Posted February 3, 2011 Author Share Posted February 3, 2011 Thank you a lot, I've yet to learn the correct way of debugging, but I'm going to soon. The problem was that my table is called "user" and I used in the query "users" with an "s" at the end, so the query couldn't find the table. Quote Link to comment https://forums.phpfreaks.com/topic/226587-mysqli_num_rows-is-giving-me-an-error/#findComment-1169492 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.