SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: MySQL Problem

  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    UK
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    MySQL Problem

    Hiya People,

    Im having a few problems with my script, it keeps returning: "Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in E:\Projects\Under Construction\rage.php on line 36".

    I have run the query through PHPmyAdmin and it returns a result. So i cant see why this is playing up....


    Code:
                    error_reporting(0);
                    $sql = mysql_connect($server, $user, $pass);
    
                    if(!$sql)
                    {
                            echo "<b>Warning:</b> Database connection failed!";
                    }
    
                    error_reporting(2);
    
                    mysql_select_db($db);
    
                    $username = $HTTP_POST_VARS['username'];
                    $password = $HTTP_POST_VARS['password'];
    
                    $han = mysql_query("SELECT * FROM `statscms_admins` WHERE `username` = '".$username."' AND `password` = '".$password."'", $sql);
                    $num = mysql_num_rows($han); // Line 36!
                    mysql_close();
    
                    if($num < 1)
                    {
                            die("<b>Invalid Information</b>");
                    }
    Does anyone have any clever ideas? or can you spot an error in this?

  2. #2
    SitePoint Wizard Lats's Avatar
    Join Date
    Jun 2003
    Location
    Melbourne, AU
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try adding some error testing in your query line...
    PHP Code:
    $han mysql_query("SELECT * FROM `statscms_admins` WHERE `username` = '".$username."' AND `password` = '".$password."'"$sql) or die(mysql_error()); 
    That will show any problems with the query.
    Lats...

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    UK
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I knew you would answer yes that does return another error now, "No Database Selected"

    Wich turned out that in my "config.php" the variable used to set the database was not named correctly:

    I Used:
    Code:
    $dd = "heenix_ragecms";
    Instead of:
    Code:
    $db = "heenix_ragecms";

  4. #4
    SitePoint Wizard Lats's Avatar
    Join Date
    Jun 2003
    Location
    Melbourne, AU
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    All fixed - good to hear
    Lats...


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
  •