SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    chown linux:users\ /world Hartmann's Avatar
    Join Date
    Aug 2000
    Location
    Houston, TX, USA
    Posts
    6,455
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    I have looked at this code for the last 30 minutes... Any help would be greatly appreciated.
    Code:
    $connection = mysql_connect("localhost","root","") or die("Could not connect to DB");
    mysql_select_db("abraham",$connection);
    $select = "SELECT id FROM users WHERE username='$username'";
    $result1 = mysql_query($select,$connection) or die("Could not execute query!");
    $num = mysql_num_rows($result1) or die("Could not count rows!");
    It keeps on spitting out the die part of the mysql_num_rows function.

    Thanks,

  2. #2
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    If the call to mysql_num_rows() returns zero, the die() function will be called, since zero evaluates to false.

    So you should be asking yourself why your query is returning an empty result set.
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  3. #3
    chown linux:users\ /world Hartmann's Avatar
    Join Date
    Aug 2000
    Location
    Houston, TX, USA
    Posts
    6,455
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    What I am trying to do is see if that username is already registered. Should I just drop the ..or die() statement and use an if..else.. statement?

  4. #4
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    In that case, yes! You can do this:

    if (mysql_num_rows($result1)) {
    // User is registered
    } else {
    // User is not registered
    }
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  5. #5
    chown linux:users\ /world Hartmann's Avatar
    Join Date
    Aug 2000
    Location
    Houston, TX, USA
    Posts
    6,455
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    Thanks!


Bookmarks

Posting Permissions

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