1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Php and sql question...long shot tho.

Discussion in 'PHP' started by micromark, Oct 11, 2007.

  1. Brewster

    Brewster Active Member

    Messages:
    489
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    60
    #41
    oops - my mistake. Change this line:

    $userid = (int)GET['userid'];
    PHP:
    to this:

    $userid = (int)$_GET['userid'];
    PHP:
    Brew
    SEMrush
     
    Brewster, Oct 15, 2007 IP
    SEMrush
  2. micromark

    micromark Peon

    Messages:
    466
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #42
    ok ta, still get this - Parse error: parse error, unexpected '['
     
    micromark, Oct 15, 2007 IP
  3. Brewster

    Brewster Active Member

    Messages:
    489
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    60
    #43
    What line do you get the error on ?

    Brew
     
    Brewster, Oct 15, 2007 IP
  4. micromark

    micromark Peon

    Messages:
    466
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #44
    Line 7 - $userid = (int)GET_['userid'];
     
    micromark, Oct 15, 2007 IP
  5. Brewster

    Brewster Active Member

    Messages:
    489
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    60
    #45
    Change that line to this:

    $userid = (int)$_GET['userid'];
    PHP:
    Brew
     
    Brewster, Oct 15, 2007 IP
  6. micromark

    micromark Peon

    Messages:
    466
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #46
    Again I get this:

    Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource
     
    micromark, Oct 15, 2007 IP
  7. Brewster

    Brewster Active Member

    Messages:
    489
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    60
    #47
    Then I guess you have no gifts for that user. It's a bit difficult to debug without you showing exactly what the value of $userid is and what data you have in your database. Can you provide this ?

    Brew
     
    Brewster, Oct 15, 2007 IP
  8. micromark

    micromark Peon

    Messages:
    466
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #48
    Here is some data from the tables. Maybe a pic would have been better?!


    giftlogtable

    
    
    
    
    Logid Giftid Recipientid Fromid   
    7 1 nat12 Helen Edit Delete 
    10 1 nat12 helen Edit Delete 
    11 1 helen Nat12 Edit Delete 
    12 1 helen helen Edit Delete 
    
    
    
    HTML:
    gifts table

    Giftid Name Image   
    1 Kiss <img src="/gifts/Kiss.png"> Edit Delete 
    2 Hot <img src="/gifts/hot.png"> Edit Delete 
    3 Leaf <img src="/gifts/leaf.png"> Edit Delete 
    
    HTML:
     
    micromark, Oct 15, 2007 IP
  9. micromark

    micromark Peon

    Messages:
    466
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #49
    Ok, so far-

    *user send info from the form into the giftlog table, info goes in fine.

    *When user tries to see what gifts have been sent to them they is an error.(many infact!)
     
    micromark, Oct 15, 2007 IP
  10. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #50
    And how are we supposed to help if we don't know what these errors are?

    Please post all error messages. And the exactly code you're using.
     
    nico_swd, Oct 15, 2007 IP
  11. micromark

    micromark Peon

    Messages:
    466
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #51
    Ok here is every thing I have-

    Basic test form to submit data to table -

    <form action="gift.php" method="post">
    <input type="text" name="giftid" value="$name">
    <input type="text" name="recipientid" value="$recipientid">
    <input type="text" name="username" value="$username">
    <input type="submit" name="Submit" value="Submit" class="mybutton">
    </form>
    HTML:

    <form action="gift.php">from above !

    <?
    require ("config.php");
    include("functions.php");
    
    
    
    // Insert a row of information into the table "giftlog"
    mysql_query("INSERT INTO giftlog
    (Giftid, Recipientid,Fromid) VALUES('$giftid', '$recipientid', '$username' ) ")
    or die(mysql_error());
    
    
    
    echo "Data Inserted!";
    
    ?>
    
    PHP:


    To view gifts in member area -

    <?
    $username = (int)$_GET['username'];
    $result = mysql_query("SELECT giftlog.name AS name, giftlog.image
    AS image FROM giftlog
    LEFT JOIN gifts
    ON giftlog.giftid = gifts.giftid
    WHERE giftlog.recipientid=" . $username);
    
    while ($row = mysql_fetch_assoc($result))
    {
    echo $row['name'];
    echo $row['image'];
    }
    ?>
    PHP:

    error message- Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource



    Also please not I have change userid to username, I am playing around with this so either change it back or ignore it.
     
    micromark, Oct 15, 2007 IP
  12. Brewster

    Brewster Active Member

    Messages:
    489
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    60
    #52
    OK, the problem seems to be that $userid is not a numeric value. Try replacing this:

    $userid = (int)$_GET['userid'];
    PHP:
    with this:

    $userid = mysql_real_escape_string( $_GET['userid'] );
    PHP:
    and call your page like this:

    {page name}.php?userid=helen

    Brew
     
    Brewster, Oct 15, 2007 IP
  13. micromark

    micromark Peon

    Messages:
    466
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #53
    hhhmmm still getting the same error message -

    Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource.


    Would it change anything if I changed userid to username as thats is whats used on the site ?!
     
    micromark, Oct 15, 2007 IP
  14. Brewster

    Brewster Active Member

    Messages:
    489
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    60
    #54
    Yes, however if you are going to change it to this:

    $username = mysql_real_escape_string( $_GET['username'] );
    PHP:
    The you will have to call the page like this:

    {page name}.php?username=helen

    Brew
     
    Brewster, Oct 15, 2007 IP
  15. micromark

    micromark Peon

    Messages:
    466
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #55
    Ok, but really that shouldnt effect it either way. ?


    Anyhow im still get the same message. - Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource ..
     
    micromark, Oct 15, 2007 IP