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
    #21
    The code that you have posted is not enough enough to get the job done. Have you posted all of the code ? You are missing some basic elements such as getting the posted data from your form and putting it into the query, and also code for displaying the gifts in the last query that you have posted.

    I would suggest you read more tutorials on how to do this, or place a request for someone to write this for you in the services forum.

    Brew
     
    Brewster, Oct 12, 2007 IP
  2. micromark

    micromark Peon

    Messages:
    466
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #22
    Still cant get this to work..Im must be missing something...I can insert data fine, but when i send a 'gift' it does not show in the members area, I dont get a error - its just a blank page.
     
    micromark, Oct 15, 2007 IP
  3. Brewster

    Brewster Active Member

    Messages:
    489
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    60
    #23
    Can you post all of the code that you are using to display the gifts in the members area

    Brew
     
    Brewster, Oct 15, 2007 IP
  4. micromark

    micromark Peon

    Messages:
    466
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #24
    Hi this is the code im using to try and find the gifts for the specific member-
    
    
    <?php
    $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' = " . $userid);
    echo $row['$name'];
    echo $row['$image'];
    ?>
    
    
    PHP:
     
    micromark, Oct 15, 2007 IP
  5. Brewster

    Brewster Active Member

    Messages:
    489
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    60
    #25
    Try this:

    
    $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' = " . $userid);
    
    while ($row = mysql_fetch_assoc($result))
    {
    echo $row['name'];
    echo $row['image'];
    }
    
    PHP:
    Brew
     
    Brewster, Oct 15, 2007 IP
  6. micromark

    micromark Peon

    Messages:
    466
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #26
    I get this -

    Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in mygifts.php on line 8
     
    micromark, Oct 15, 2007 IP
  7. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #27
    Remove all single quotes from the query string. And does $userid contain the expected content?
     
    nico_swd, Oct 15, 2007 IP
  8. micromark

    micromark Peon

    Messages:
    466
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #28
    Ok removed all quotes. - Get same error.

    I dont have a column called $userid

    I have just made the tables like you said -

    One called gitfs, with 3 fields.
    - Giftid
    - Name
    - Image

    And another one called giftlog or something like that, with 4 fields.
    - Logid
    - Giftid
    - Recipientid
    - Fromid
     
    micromark, Oct 15, 2007 IP
  9. Brewster

    Brewster Active Member

    Messages:
    489
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    60
    #29
    Are you using mysql_connect to connect to the database ? You havent got this in the code you posted, but I just want to rule out the obvious.

    Brew
     
    Brewster, Oct 15, 2007 IP
  10. micromark

    micromark Peon

    Messages:
    466
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #30
    Yes its connecting.
     
    micromark, Oct 15, 2007 IP
  11. Brewster

    Brewster Active Member

    Messages:
    489
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    60
    #31
    What value does the variable $userid contain ?

    Brew
     
    Brewster, Oct 15, 2007 IP
  12. micromark

    micromark Peon

    Messages:
    466
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #32
    Im slightly confused about the- $userid

    I do not have this in the table. (I dont think im supposed to.)


    Does this help:

    
    
    // Insert a row of information into the table "giftlog"
    mysql_query("INSERT INTO giftlog
    (Giftid, Recipientid,Fromid) VALUES('$giftid', '$recipientid', '$userid' ) ")
    or die(mysql_error());
    
    
    PHP:
     
    micromark, Oct 15, 2007 IP
  13. Brewster

    Brewster Active Member

    Messages:
    489
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    60
    #33
    On the page where you are displaying the gifts, the variable $userid needs to contain the id of the user that the gifts belong to. Are you populating this variable ? If not, that is where the problem lies.

    Brew
     
    Brewster, Oct 15, 2007 IP
  14. micromark

    micromark Peon

    Messages:
    466
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #34
    Do you mean the form that submits the data?
     
    micromark, Oct 15, 2007 IP
  15. Brewster

    Brewster Active Member

    Messages:
    489
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    60
    #35
    No, I mean the page that displays the gifts. Can you post the code that you have for that page.

    Brew
     
    Brewster, Oct 15, 2007 IP
  16. micromark

    micromark Peon

    Messages:
    466
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #36
    Brew: your a big help. Thanks in advance.


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






    <?php

    $query = mysql_query("SELECT * FROM gifts")
    OR die(mysql_error());
    while ($gift = mysql_fetch_array($query))
    {
    echo $gift['Name'];

    echo $gift['Image'];





    }


    ?>
     
    micromark, Oct 15, 2007 IP
  17. Brewster

    Brewster Active Member

    Messages:
    489
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    60
    #37
    Hi again

    I meant the page that had your code that looks something like this:

    $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=" . $userid);
    
    while ($row = mysql_fetch_assoc($result))
    {
    echo $row['name'];
    echo $row['image'];
    }
    PHP:
    The variable $userid needs to have a value, otherwise nothing will get displayed. Try this:

    
    $userid = (int)GET['userid'];
    
    $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=" . $userid);
    
    while ($row = mysql_fetch_assoc($result))
    {
    echo $row['name'];
    echo $row['image'];
    }
    PHP:
    Then call the page like this {name of page}.php?userid=13 - use a value that is in your database here.

    Understand ?

    Brew
     
    Brewster, Oct 15, 2007 IP
  18. micromark

    micromark Peon

    Messages:
    466
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #38
    Ok do i put that all together in the <? tags ?>
     
    micromark, Oct 15, 2007 IP
  19. micromark

    micromark Peon

    Messages:
    466
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #39
    Ok i get this - Parse error: parse error, unexpected '['
     
    micromark, Oct 15, 2007 IP
  20. micromark

    micromark Peon

    Messages:
    466
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #40
    This is the code that you wanted btw


    $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' = " . $userid);
    while ($row = mysql_fetch_assoc($result))
    {
    echo $row['Name'];
    echo $row['Image'];
    }
     
    micromark, Oct 15, 2007 IP