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 ...
- 04-28-2009 #1Linux 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.
- 04-28-2009 #2Just Joined!
- Join Date
- Apr 2009
- Posts
- 90
$_SESSION["username"] = $validatedName;
? maybe I misunderstand you.
- 04-29-2009 #3Linux 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.
- 04-29-2009 #4Just 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.
- 04-29-2009 #5Linux 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.
- 04-29-2009 #6
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.
- 04-29-2009 #7Linux Newbie
- Join Date
- Dec 2006
- Posts
- 119
first form when they input their information:
then is being stored: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>
here is the verification form:PHP Code:$_SESSION['username'] = $newSuperGlobal['username'];
hope this could help you guys to help meHTML 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']; ?> <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>
. 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.
- 05-07-2009 #8Linux Newbie
- Join Date
- Dec 2006
- Posts
- 119
no thoughts anybody

?!
- 05-07-2009 #9
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.
- 05-11-2009 #10Linux 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.


