need some PHP Help

Discussion in 'HTML & Website Design' started by tick20045, Jan 27, 2010.

  1. #1
    if I have a script like this:

    <?php 
    $fetch_users_data = mysql_fetch_object(mysql_query("SELECT * FROM `members` WHERE username='".$_SESSION['username']."'"));
    
    $ref_id=$fetch_users_data->id;
    if(isset($_GET['join'])){
    	$referral_ID = $_GET['join'];
    	$referral_string= "?join=".$referral_ID;
    }
    $membername= $fetch_users_data->username; //don't change
    
    ?>
    Code (markup):
    and I want to add
    a $subid

    whitch code is correct:

    $subid = $_SESSION['username'];
    Code (markup):
    or

    $subid = $membername;
    Code (markup):
    please someone who knows php and not just quesses. Thx guys.

    let me explain a bit better what I want. I want $subid to be the username curently logged in.
     
    Last edited: Jan 27, 2010
    tick20045, Jan 27, 2010 IP
  2. jwitt98

    jwitt98 Peon

    Messages:
    145
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Well since you already have the username stored in a session variable ( it's being used in the first query to query the database to fetch the users data), then you should just use the session variable.
    Also, if you want to use this on more than just the current page, you will have to use sessions. If you assigned the username to a regular variable, it would be lost as soon as you left the page.

    Another thing, is that if the query should happen to fail, then $membername would not be set.
     
    Last edited: Jan 27, 2010
    jwitt98, Jan 27, 2010 IP