Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11
i might have a easy question about php sessions. what i am trying to do is to replace the session with a new value inputted by the user. so, let ...
  1. #1
    Linux Newbie
    Join Date
    Dec 2006
    Posts
    119

    [SOLVED] PHP Sessions

    i might have a easy question about php sessions. what i am trying to do is to replace the session with a new value inputted by the user.

    so, let say that i have "form1". the user inputs under their user name "Jor". then that is being store on "$_SESSION['username']". So, after that they will go to verify that they inputted their user name properly. on the verify they will click edit, type their new user name which is "Joe"... and this is the part that i am getting stuck.

    i currently have "Jor" in "$_SESSION['username']"...
    so how i could replace "Jor" "$_SESSION['username']" with "Joe" new input session?

    thank you for your help in advance.

  2. #2
    Just Joined!
    Join Date
    Apr 2009
    Posts
    90
    $_SESSION["username"] = $validatedName;

    ? maybe I misunderstand you.

  3. #3
    Linux Newbie
    Join Date
    Dec 2006
    Posts
    119
    touchtecservers,
    no you didn't. let me explain better.

    1) user name input = "Jor"
    user name store = $_SESSION['username'] = $validatedName
    2) user name verify. User realizes that misspell his/her user name so decide to change it.
    new user name = "Joe"
    new user name store = ?
    this last part is when i am having trouble. once i have that session going how i could replace it?

    hopefully this make sense. thanks for your help.

  4. #4
    Just Joined!
    Join Date
    Apr 2009
    Posts
    90
    Well, a session works just like a persistent variable.

    Just use the $_SESSION["username"] = $newUsername;
    And it will overwrite the old value.

  5. #5
    Linux Newbie
    Join Date
    Dec 2006
    Posts
    119
    that is the way i have it, but it doesn't instert anything. what i am doing is that i have an "edit button" in the verification form. so if they inputted anything on that the value will be replaced. with the new one. but apparently the session is not getting replaced.

    hopefully this make sense. let me know if it doesn't.

  6. #6
    Trusted Penguin elija's Avatar
    Join Date
    Jul 2004
    Location
    Either at home or at work or down the pub
    Posts
    2,300
    This is a very simple sample

    Code:
    <?php
    	$name = "Joe Doe";
    	$_SESSION['name'] = $name;
    	echo $_SESSION['name'];
    
    	$name = "John Doe";
    	$_SESSION['name'] = $name;
    	echo $_SESSION['name'];
    ?>

    So using Posted form data it might look like this

    Code:
    <?php
    	$name = "Joe Doe";
    	$_SESSION['name'] = $name;
    	echo $_SESSION['name'];
    
    	$name = $_POST['name'];
    	$_SESSION['name'] = $name;
    	echo $_SESSION['name'];
    ?>

    Can you post your code or is this homework? ( )
    If we hit that bullseye, the rest of the dominoes will fall like a house of cards. Checkmate! (Zapp Brannigan)


    My new blog. It's probably not as good as I think it is.

  7. #7
    Linux Newbie
    Join Date
    Dec 2006
    Posts
    119
    first form when they input their information:
    HTML Code:
    <tr>
    <td width="150">Username: <span class="required">*</span></td>
    <td><input name="username" type="text" size="45" maxlength="45" onblur="validate(this,'RequiredAlphabetic')" /></td>
    </tr>
    then is being stored:
    PHP Code:
    $_SESSION['username'] = $newSuperGlobal['username']; 
    here is the verification form:
    HTML Code:
    <tr>
    <td width="150" class="left" ><label >Username: <span class="required">*</span></label></td>
    <td class="left" ><div id="usernameSelected"><?php echo $_SESSION['username']; ?>&nbsp;&nbsp;<a href="#" class="edit" onClick="usernameEdit()">edit</a></div>
    <!-- -->
    <div id="usernameEdit"><input type="text" size="20" name="username" class="text" value="<?php echo $_SESSION['username']; ?>" id="username"  onblur="validate(this,'RequiredAlphabetic')"  /></div></td>
    </tr>
    hope this could help you guys to help me . just to make sure... what i want to do is...
    IF the user doesn't edit the verification form then print out that value (username session)....
    IF the user does edit in the verification form then print out that NEW value (username session).

    i hope that now make more sense.
    thanks for you help in advance.

  8. #8
    Linux Newbie
    Join Date
    Dec 2006
    Posts
    119
    no thoughts anybody

    ?!

  9. #9
    Trusted Penguin elija's Avatar
    Join Date
    Jul 2004
    Location
    Either at home or at work or down the pub
    Posts
    2,300
    I was sure I already posted this... Ah well...

    Assuming your form has a method = post

    $_SESSION['username'] = $newSuperGlobal['username'];

    becomes

    $_SESSION['username'] = $_POST['username'];
    If we hit that bullseye, the rest of the dominoes will fall like a house of cards. Checkmate! (Zapp Brannigan)


    My new blog. It's probably not as good as I think it is.

  10. #10
    Linux Newbie
    Join Date
    Dec 2006
    Posts
    119
    thnx for your help, but that still hasn't solve my problem. that is exacly where i am getting an error. whenever i try to edit the form under the verification process and replace the session it doens't replace it. it just store a blank value. so your method i've tried to use it but still doesn't work.

    thanks for your help anyways.

Page 1 of 2 1 2 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...