Please help!! (newbie question)

Discussion in 'PHP' started by candle21428, Oct 3, 2006.

  1. #1
    I would like to get the affiliate id by using the username from database (all data were created already). Say when someone click on the following link:

    www.xx.com/yy.php?id=[whatever the username is]

    I can display in content with <?$q2[affiliateid]?> to show his/her affiliateid.

    Here is part of the code:


    $q2 = mysql_query("SELECT AffiliateID FROM Affiliates WHERE Username = $id");
    if (!$row2 = mysql_fetch_array($q2)) {
    print (mysql_error());
    }


    The above code is not working properly, but I was able to display the username correctly if the link is www.xx.com/yy.php?id=[affiliateid] (when I change the code)

    One more thing: If I change the code to

    $q2 = mysql_query("SELECT AffiliateID FROM Affiliates WHERE Username = 'rath12343' <===[one of the username on database]");

    everything works perfectly.

    What did I do wrong here?

    Any idea?
     
    candle21428, Oct 3, 2006 IP
  2. BRUm

    BRUm Well-Known Member

    Messages:
    3,086
    Likes Received:
    61
    Best Answers:
    1
    Trophy Points:
    100
    #2
    Hmm try putting ' ' around the $id.
     
    BRUm, Oct 3, 2006 IP
  3. vdd

    vdd Peon

    Messages:
    34
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    $q2 = mysql_query("SELECT AffiliateID FROM Affiliates WHERE Username = '$id'");
     
    vdd, Oct 3, 2006 IP