SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist
    Join Date
    Jan 2005
    Location
    ireland
    Posts
    482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    mysql_fetch_array() driving me nuts !

    I keep getting the follwing error with this piece of code


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


    ------------------ Code -------------------------------

    $c1 = $_SESSION['subject_id'];

    $query_result = mysql_query ("SELECT * FROM subjects WHERE subject_id = '$c1'");

    while ($row = mysql_fetch_array ($query_result, MYSQL_NUM))

    {
    $cc1 = $row[2];
    echo "<p>You have choosen to give grinds for the <font size='+1'> $cc1 </font></p>";
    }



    Tks

  2. #2
    SitePoint Addict toggg's Avatar
    Join Date
    Jan 2005
    Location
    Auvergne/France
    Posts
    253
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi
    Allways say:
    PHP Code:
    $query_result mysql_query ("SELECT * FROM subjects WHERE subject_id = '$c1'")
     or die(
    'Error query'.musql_error()) ; 
    So you see if the query succeeded.
    BTW is script connected when it does that ?
    +
    bertrand Gugger toggg.com linux, PHP, Auvergne/France open source

  3. #3
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, firstly a mysql_fetch_array() error is almost always caused by a problem in the mysql query string.

    I would assume that either there is nothing to return in products (there shouldnt be an error anyway), you have created a misleading variable ($c1), you have misnamed the table.

    Firstly i would try putting "" around the subject_id field.

    If that does not work try the above, then see indeed see if the script has been connected all. Do this by typing echo "hello"

  4. #4
    SitePoint Evangelist
    Join Date
    Jan 2005
    Location
    ireland
    Posts
    482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Tks guys my table name was incorrect, i feel ashamed

  5. #5
    SitePoint Addict toggg's Avatar
    Join Date
    Jan 2005
    Location
    Auvergne/France
    Posts
    253
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    most stupid, most to be searched
    nevertheles allways test the error on query but also connect
    bye
    bertrand Gugger toggg.com linux, PHP, Auvergne/France open source


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
  •