SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Guru
    Join Date
    Apr 2001
    Location
    BC, Canada
    Posts
    630
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    little help?
    here is the error
    Warning: Supplied argument is not a valid MySQL result resource in /www/welcometovernon/coupons/update.php on line 84


    here is that line
    $result =mysql_query("SELECT * FROM coupons WHERE username=$username",$db);

    Im already connect to the database and everything.. the table is called coupon.. username is a variable sent through a form, and is also the name of one of the collums in the database

    any ideas?
    thanx

  2. #2
    SitePoint Enthusiast RandMan's Avatar
    Join Date
    Mar 2001
    Location
    Crossville, TN USA
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You say your TABLE is "coupon" but your query is selecting from "coupons".

  3. #3
    SitePoint Guru
    Join Date
    Apr 2001
    Location
    BC, Canada
    Posts
    630
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    er..

    i mean its called coupons

    sorry

  4. #4
    SitePoint Enthusiast RandMan's Avatar
    Join Date
    Mar 2001
    Location
    Crossville, TN USA
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just looked at my scripts to confirm. I always use single quotes around my variables:

    "SELECT * FROM coupons WHERE username='$username'"

    If that doesn't clear it up the only other thing could be your link to the connection - $db.

    Make sure the link is still valid and you have not reused that variable.

    BTW. Once you connect to your db you do not need to use the link in your query.

    $result = mysql_query($query);
    or
    $result = mysql_query($query,$db);

    will both work.

  5. #5
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I write my code like below because I find that I'm always having to debug my sql statements to find out where I have made a silly mistake. As Randman suggests, use single quotes around $username. Also, check that username holds a value and is not just an empty string.

    $sql = "SELECT * FROM coupons WHERE username='$username'"
    echo $sql; // print out the sql string for debugging purposes.
    $result =mysql_query,($sql,$db);

  6. #6
    SitePoint Enthusiast RandMan's Avatar
    Join Date
    Mar 2001
    Location
    Crossville, TN USA
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sid
    I'm glad you said that. I always echo my sql's during development cycle. In fact, after each process and periodically through the program I echo all my variables. Makes it real easy to debug.

    It's an old programmer's trick. Back in the old days when they had keypunch departments and programs were carried in boxes of cards, it might take several days before your program could be executed. Variable checking could cut weeks and months off the development cycle.

    Gosh, how did we do it then. No wonder I have gray hair. I love programming today.


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
  •