Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder
    Join Date
    Feb 2010
    Posts
    130
    Thanks
    4
    Thanked 0 Times in 0 Posts

    mysql_fetch_array(): supplied argument is not a valid MySQL result resource

    This is the error I get:

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in <b>/mounted-storage/home49a/sub006/sc33133-WBJC/rpgmax.com/wp-content/themes/gameup-single-pro/header-gameprofile.php</b> on line <b>21</b><br />
    - Game Profile - RPGMAX</title>
    This is the code in the file:

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>
    <head profile="http://gmpg.org/xfn/11">
    <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />
    <!-- Title -->
            <title>
    <?php
    /*
        Connects to the database using the following settings:
        Host: hidden
        Username: hidden
        Password: hidden
    */
    $connection mysql_connect("hidden","hidden","hidden");

    //Selects the Games table
    mysql_select_db("rpgmax"$connection);

    $gameId $_GET['gameId'];
    $result mysql_query("SELECT * FROM wp_rpgmax_games WHERE gameId=$gameId");
    $row mysql_fetch_array($result);
    echo 
    $row['gameName'];
    ?>
     - <?php wp_title(''); ?> - <?php bloginfo('name'); ?></title>
    This is the same code I use at MMOCraze.com

    My code there is:

    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
        <head>
            <!-- Title -->
            <title>
    <?php
    /*
        Connects to the database using the following settings:
        Host: hidden
        Username: hidden
        Password: hidden
    */
    $connection mysql_connect("hidden","hidden","hidden");

    //Selects the Games table
    mysql_select_db("mmocraze"$connection);

    $gameId $_GET['gameId'];
    $result mysql_query("SELECT * FROM wp_MMOCraze_games WHERE gameId=$gameId"); 
    $row mysql_fetch_array($result); 
    echo 
    $row['gameName'];
    ?>
     - <?php wp_title(''); ?> - <?php bloginfo('name'); ?></title>
    with no error in the file...

    Any ideas with what's wrong with the code on RPGMax?

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    $result = mysql_query("SELECT * FROM wp_MMOCraze_games WHERE gameId=$gameId");
    You should add proper error checks to your query, like
    PHP Code:
    $result mysql_query("SELECT * FROM wp_MMOCraze_games WHERE gameId=$gameId") or die(mysql_error()); 
    PS: Sanitise all external inputs before usingin queries to prevent sql injection. Read http://php.net/manual/en/security.da...-injection.php
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Regular Coder
    Join Date
    Feb 2010
    Posts
    130
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Tried that and got this error message:

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
    which makes no sense to me....

    by the way, the mysql_fetch_array() error occurs on one site but NOT the other...BOTH sites are using the exact same mysql_fetch_array() code, which makes me wonder what the problem is...

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    which makes no sense to me....
    Change
    PHP Code:
    $result mysql_query("SELECT * FROM wp_MMOCraze_games WHERE gameId=$gameId") or die(mysql_error()); 
    to
    PHP Code:
    $sql="SELECT * FROM wp_MMOCraze_games WHERE gameId=$gameId";
    $result mysql_query($sql) or die(mysql_error(). '<br>query: '.$sql); 
    to get more clues.

    Also add
    PHP Code:
    print_r($_GET); 
    at the top of your code to see the values inside $_GET array.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #5
    Regular Coder
    Join Date
    Feb 2010
    Posts
    130
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Error:

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1<br>query: SELECT * FROM wp_rpgmax_games WHERE gameId=

  • #6
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    query: SELECT * FROM wp_rpgmax_games WHERE gameId=
    Isn't obvious now? That seems the variable $gameId (and $_POST['gameId']) is empty. Did you see the other diagnostic in my last post?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #7
    Regular Coder
    Join Date
    Feb 2010
    Posts
    130
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Error after adding the print_r code:

    Array
    (
    )
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1<br>query: SELECT * FROM wp_rpgmax_games WHERE gameId=
    by the way, gameId is a variable in my database that HAS data in it. In my code, it matches up with its counterpart:

    PHP Code:
    $gameId $_GET['gameId']; 
    PHP Code:
    $sql="SELECT * FROM wp_rpgmax_games WHERE gameId=$gameId"

  • #8
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Quote:
    Array
    (
    )
    Your $_GET array is empty. How does your variable $gameId get some value then? Could you post the url the page that you work on?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #9
    bdl
    bdl is offline
    Regular Coder
    Join Date
    Apr 2007
    Location
    Camarillo, CA US
    Posts
    590
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Quote Originally Posted by crazykid View Post
    Error after adding the print_r code:



    by the way, gameId is a variable in my database that HAS data in it. In my code, it matches up with its counterpart:

    PHP Code:
    $gameId $_GET['gameId']; 
    PHP Code:
    $sql="SELECT * FROM wp_rpgmax_games WHERE gameId=$gameId"
    Just to be clear here, `gameId` isn't a variable in your database, it's a field in a table (`wp_rpgmax_games`). The variables referenced are $gameId and $_GET['gameId'] (technically an array index).

    While it's nice to have a consistent naming convention, you want to be aware there is a distinction between a variable in PHP and a field in MySQL. You can name the PHP variable `froozle` if you want (though I don't recommend it), it's still the data contained in the var and the target that matters.

    Here's a tip regarding naming conventions that I like to use: name your HTML input fields something like "input_gameId" and then the corresponding $_POST (or $_GET) index will be $_POST['input_gameId']. This helps you differentiate between incoming, unsanitized and unvalidated data and the actual data you intend to interact with the database. Once it is has been verified / cleaned up, you can rename it "$clean_gameId" (or something similar).

  • #10
    Regular Coder
    Join Date
    Feb 2010
    Posts
    130
    Thanks
    4
    Thanked 0 Times in 0 Posts
    http://rpgmax.com/mmo/gamedirectory/

    Click on ANY of the links...they are coded to lead to a http://rpgmax.com/mmo/gamedirectory/...le/?gameId=XXX page but they dont...they lead directly do a /gameprofile/ page.

    Now go to http://mmocraze.com/game-directory and click on any of the links. They WORK...they lead to an actual game profile page with a gameId connected to the URL.

    Both sites are hosted on the same hosting server, use same seo settings, use same files (with different database info but databases have same structure). RPGMax is the one that has the problems though.


  •  

    Posting Permissions

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