SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,388
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Why is there a warning over this simple line of code?

    I get the following warning:

    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\media\rs_details.inc.php on line 18

    Line 18 is marked in the code:

    PHP Code:
    if (isset($_REQUEST['details'])) 

        
    $ID $_REQUEST['details']; 
        
    $ID strip_tags($ID); // REMOVE SYMBOLS 
        
    $ID trim($ID);       // REMOVE ANY EXTRA WHITE SPACE AT END OF LINE 
        
    $ID htmlspecialchars($ID);
    var_dump($ID); // RETURNS: string(2) "37". [37 IS THE CORRECT VALUE]
    $sql mysql_query 
        
    ("SELECT ID, ModelName, OwnerName, Filename, Descr, Approved
        FROM racerspotlight
        WHERE (ID LIKE 
    $ID) AND (Approved LIKE 'y')
        "
    );
    var_dump($sql); // RETURNS: bool(false) 

    $rows mysql_num_rows($sql); // <<<<< LINE 18
    var_dump($rows); // RETURNS: bool(false) 
    A var_dump of $ID returns the true value. When I use that value in phpMyAdmin in the above query (replacing $ID for the correct value), it returns the correct row. Why then does the var_dump for the $sql not show this? I am puzzled why there's an error notice for a simple line of code.

    Any help will be appreciated.

    Thanks!
    Steve

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,508
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Put this after the query (and before the dump):
    PHP Code:
    if (!$sql) {
        die(
    'Invalid query: ' mysql_error());

    What error does it give?

  3. #3
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,388
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    It says: Invalid query: Can't connect to MySQL server on 'localhost' (10061)

    The other pages connect and display fine that lead up to this page, so why should it have trouble connecting? The top of the page says:
    require_once ('../includes_php/connect.php');

    Thanks!

  4. #4
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Is this problem script in a nested folder, or further up or down your file system?

    If so you will need to change the ../ in your include.

    Either that or deal with the real problem which is you probably not setting your include directory to includes_php.

    Setting your include directories options Man page

    You probably want to just do this:

    include("connect.php");

    and not worry about which directory you are in.

  5. #5
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,388
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I made a whole mess of changes and am currently working on other problems with this page. We can close this discussion.

    Thanks for helping!


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
  •