Results 1 to 4 of 4

Thread: mysql_fetch_array(): supplied argument . . .

  1. #1
    Join Date
    Aug 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default mysql_fetch_array(): supplied argument . . .

    PHP Code:
    <?php
    if (isset($_COOKIE["login"])) {

    $con mysql_connect("localhost","example","password");
    if (!
    $con)
      {
      die(
    'Could not connect: ' mysql_error());
      }

    mysql_select_db("example_database"$con);

    $result mysql_query("SELECT * FROM `users`
    WHERE `username`=
    $_COOKIE[login]");

    while(
    $row mysql_fetch_array($result))
      {
    $cash $row['money'] - '25';
    echo 
    'Cash: ' $cash '<br> <a href=test.php> Back to the pencil Shop! </a>';
    }


    mysql_query("UPDATE `users` SET `money` = '$cash'
    WHERE `username` = '
    $_COOKIE[login]'");

    mysql_close($con);



    } else {
      echo 
    "Welcome guest!<br />";
    }
    ?>
    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/spiterz2/domains/battlecraft.cankoo.com/public_html/buy.php on line 15

    Thats my code, and underneath is the error i get =S I cant solve it.

  2. #2
    Join Date
    Feb 2006
    Posts
    236
    Thanks
    8
    Thanked 3 Times in 3 Posts

    Default

    For one thing, looks to me that $result is probably a null string, returned because the initial look-up failed. You should probably test $result to make sure that the cookie is valid anyways. The error probably ocurred because of missing quotes:
    Code:
    $result = mysql_query("SELECT * FROM `users`
    WHERE `username`=$_COOKIE[login]");
    should be
    Code:
    $result = mysql_query("SELECT * FROM users WHERE username = $_COOKIE['login']");
    And don't use backticks around the MySQL variables. The quotes are missing in a line farther down as well.....

    And there could be more.....

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    $result = mysql_query("SELECT * FROM users WHERE username = $_COOKIE['login']");
    Should be:
    $result = mysql_query("SELECT * FROM users WHERE username = {$_COOKIE['login']}");
    When using complex variables in double quotes, you must use braces to distinguish the variable from the rest of the string.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #4
    Join Date
    Feb 2006
    Posts
    236
    Thanks
    8
    Thanked 3 Times in 3 Posts

    Default

    Oops! Forgot that important one....

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
  •