SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Non-Member
    Join Date
    Jan 2004
    Location
    Seattle
    Posts
    4,328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Why is mysql_query not a valid MySQL result resource?

    I adapted this script from another website, but, for some reason, it doesn't work on my new website. It gives the familiar error message, "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource," with or without the WHERE clause.

    Any idea what the problem might be?

    PHP Code:
    <?php
    $result 
    mysql_query('select count(*) from gw_geog_pol');
    if ((
    $result) && (mysql_result ($result 0) > 0)) {
    }
    else {
    die(
    'Invalid query: ' mysql_error());
    }
    {
    $Children mysql_query ("SELECT * FROM gw_geog_pol
      WHERE Parent = 'Canada'"
    );
    }
    ?>

    <?php
    echo '<table style="margin-left: auto; margin-right: auto;">';
    while (
    $row mysql_fetch_array($ChildrenMYSQL_ASSOC))
    {
    (
    etc.)

  2. #2
    SitePoint Addict
    Join Date
    Nov 2005
    Posts
    327
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why do you have curly brackets here with no control structure keyword (if, else, while, etc.)?

    PHP Code:
    {
    $Children mysql_query ("SELECT * FROM gw_geog_pol
      WHERE Parent = 'Canada'"
    );


  3. #3
    Non-Member
    Join Date
    Jan 2004
    Location
    Seattle
    Posts
    4,328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by a.dotty.dot
    Why do you have curly brackets here with no control structure keyword (if, else, while, etc.)?

    PHP Code:
    {
    $Children mysql_query ("SELECT * FROM gw_geog_pol
      WHERE Parent = 'Canada'"
    );

    I'm not sure what the curly brackets are for, unless it's just to help keep things organized or make it easier to understand. There are simliar curly brackets on my oriqinal script, which works.

    I deleted them, but that didn't fix the problem:

    PHP Code:
    <?php
    $result 
    mysql_query('select count(*) from gw_geog_pol');
    if ((
    $result) && (mysql_result ($result 0) > 0)) {
    }
    else {
    die(
    'Invalid query: ' mysql_error());
    }
    // WHERE Parent = '$_GET[$MyGet]'");
    $Children mysql_query ("SELECT * FROM gw_geog_pol");
    ?>

  4. #4
    SitePoint Addict
    Join Date
    Nov 2005
    Posts
    327
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't see any reason why it shouldn't be a valid resource. Let's see what happens when you add error checking to this line:

    PHP Code:
    $Children mysql_query ("SELECT * FROM gw_geog_pol") or die(mysql_error()); 

  5. #5
    SitePoint Zealot Anagram's Avatar
    Join Date
    Feb 2003
    Location
    Norway
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Uhm, have you connected to your database?

    The normal flow for such errors is this:

    Warning: mysql_connect(): Can't connect to MySQL server on 'localhost' in somefile.php on line x

    Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in somefile.php on line y

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in somefile.php on line z

    Here, try this: http://www.codedemons.net/index/tips...esult-Resource

    -Anagram
    If pigs could fly, the prize of bacon would reach the sky.

    www.dosspirit.net - Norwegian
    reviews of DOS games

  6. #6
    Non-Member
    Join Date
    Jan 2004
    Location
    Seattle
    Posts
    4,328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, I fixed it. Thanks for all the tips.


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
  •