Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,447
    Thanks
    71
    Thanked 102 Times in 101 Posts

    mysql_num_rows finding a match

    This is a PHP question. I need to find if a username already exists in the database. I tried returning TRUE and == 1 but neither are working.
    I'd like to avoid using a while loop or foreach if possible. Thanks

    PHP Code:
    $checkuser mysqli_query($con,"SELECT username FROM rod_AllUsers WHERE username='$username'");
     
    $checkuserrow mysql_num_rows($checkuser);
     

     
    //ERROR
     
    if ($checkuserrow == 1) {
        echo 
    'This username already exists. Please go back and choose another one.';
             die;
     } 
    Been a sign maker for 7 years. My business:
    American Made Signs

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,641
    Thanks
    0
    Thanked 649 Times in 639 Posts
    You are getting mysql_ and mysqli_ calls mixed up. Add the "i" into mysqli_num_rows and it should then work.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • Users who have thanked felgall for this post:

    myfayt (04-26-2014)

  • #3
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,447
    Thanks
    71
    Thanked 102 Times in 101 Posts
    Thanks so much Felgall. It's amazing what one little letter missing can do.
    Been a sign maker for 7 years. My business:
    American Made Signs


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •