I need some php help

Discussion in 'PHP' started by bthomas312, Apr 18, 2011.

  1. #1
    For some reason I this part of the code is not working like it should.

    $thename = $_SESSION['user_id'];
    $user = $_SESSION['user_id'];


    //Check for user
    if(!isset($_SESSION['user_id']))
    { header("location: signout.php"); }

    echo"...the..$thename...n.$user........"; I put this in here to see what the two values were and they are right at this point.

    //AJAX Function
    if( (isset($_REQUEST['auth'])) && ($_REQUEST['auth'] == "cc22") ) {


    $user = $thename;

    echo"user...$user..."; //for some reason this echo does not display on the page???

    $amount = $_REQUEST['amount'];
    $id = $_REQUEST['cid'];



    if(isset($_SESSION['user_id']))
    $user = $_SESSION['user_id'];

    $d = new donation();
    $d->cause_id = $id;
    $d->user_id = $user;
    $d->amount = $amount;
    $d->verified = 0;
    $d->tran_date = date('Y-m-d h:i:s', time());
    $d->Save(); //when this is called all the values are saved to the database but $user is set to 0 for some reason when it should not be.
    die();
    }



    What is odd, if i set a static value to the $user var it will save that value in the database but if i change it back to get the session value then it always uses 0 even tho in the first echo it will echo the right number for $user. Any ideal?
     
    bthomas312, Apr 18, 2011 IP
  2. AdM.as

    AdM.as Peon

    Messages:
    20
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You seem to be redefining the same $user variable multiple times through the code - is this code all from a single page or is it split up?

    If the code is split up, what could possibly be happening is either the $user or $_SESSION['user_id'] variable is being reset somewhere in your code. If it's split up, could you paste the entire code on here (unless it's huge then use pastebin)?
     
    AdM.as, Apr 18, 2011 IP
  3. bthomas312

    bthomas312 Peon

    Messages:
    65
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    this is all in the same file
     
    bthomas312, Apr 18, 2011 IP
  4. AdM.as

    AdM.as Peon

    Messages:
    20
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I'm not sure exactly why, from looking at this code alone, it would be setting the $user variable to 0. You can try commenting out the $user = $thename; and the 2nd $user = $_SESSION['user_id']; as you are just redefining it with the same value.

    It seems like the $user variable is getting changed somehow... you could use the $thename in place of $user and if that's echoing/saving correctly, then it's most likely an issue with your $user var getting messed with.
     
    AdM.as, Apr 18, 2011 IP