SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist N9ne's Avatar
    Join Date
    Aug 2002
    Location
    England
    Posts
    581
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Why can't I use mysql_num_rows in a function?

    PHP Code:
    function isAdmin($username$password)
    {
     global 
    $connect$select_db$adminstable;
      
    $query mysql_query("SELECT userid FROM $adminstable WHERE username = '$username' AND password = '$password'");
      if(
    mysql_num_rows($query) > 0)
        return 
    true;
      else
        return 
    false;

    I get an error thrown at me because of the mysql_num_rows, I'm stumped, I don't know why it's got a problem with it? It works in a normal PHP file but not in a function...

    Also, if it's a known problem and rule that I can't have in there, what alternative do I have?

  2. #2
    SitePoint Zealot
    Join Date
    Jun 2003
    Location
    Middle / East TN
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $connect and $select_db are only variables, you still have to make the connection. You can do this outside or inside the function, as long as it's before your use the $query.
    There are 10 kinds of people in this world,
    those who can read binary and those who can't.

  3. #3
    SitePoint Evangelist N9ne's Avatar
    Join Date
    Aug 2002
    Location
    England
    Posts
    581
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The connection is made before the function...

  4. #4
    SitePoint Zealot
    Join Date
    Jun 2003
    Location
    Middle / East TN
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh yeah, sometimes it throws an error if the query is faulty. Print out the query with whatever is being used of username and pass to make sure username, pass and the table variables are set.
    There are 10 kinds of people in this world,
    those who can read binary and those who can't.


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
  •