SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru
    Join Date
    Apr 2001
    Location
    BC, Canada
    Posts
    630
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey, new to the php/mysql scene and if possible could I get a little help?

    Im gettin this error

    Warning: Supplied argument is not a valid MySQL result resource in /www/welcometovernon/coupons/update.php on line 9

    line 9 reads...
    $num = mysql_num_rows($result);


    everything up to that point..

    @mysql_connect("localhost", "welcometovernon", "bob123")
    or die("Unable to connect");
    $result = @mysql_db_query("coupons", "SELECT * FROM coupons WHERE username = '$username' AMD (password = '$password')");

    $num = mysql_num_rows($result);

    password and username are coming from a page before this in a form..

    Any ideas?

    thanx
    talk to you later

  2. #2
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The error is caused because your call to mysql_db_query() failed to return a result set identifier.

    Some problems:

    1) int mysql_db_query (string database, string query [, int link_identifier])
    From the signature you can see that the first arguement is the database name. Is coupons the name of the database or just a table. In most cases, a script only needs to access one database. Therefor, I usually see ppl write their code like this:
    PHP Code:
    $conn = @mysql_connect("localhost""welcometovernon""xxxxxx"
       or die(
    "Unable to connect"); 
    @
    mysql_select_db("dbname"$conn
       or die( 
    "Unable to connect");

    $result mysql_query("SELECT * FROM coupons WHERE username = '$username'
                                             AND password = '
    $password'"); 
    $num mysql_num_rows($result); 
    2) AMD make computer chips, you want AND

  3. #3
    SitePoint Guru
    Join Date
    Apr 2001
    Location
    BC, Canada
    Posts
    630
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    "coupons" is a database that has the table "coupons" in it

  4. #4
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well most likely there is a problem with your SQL statement. Insert this line of code somewhere:
    PHP Code:
    echo "SELECT***FROM*coupons*WHERE*username*=*'$username'   
       AND*password*=*'
    $password'"
    And see if it prints the SQL statement you expect to your browser. Also, you can then copy and paste this from your browser and run the sql from the command line (or from phpMyAdmin) and see what the result is.


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
  •