By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,462 Members | 1,057 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,462 IT Pros & Developers. It's quick & easy.

changing value of empty session variable with another variable defined in form

P: 1
How can I change the value of empty session variable with another variable value defined in form. I get value of session value of id from a logon form , that is "". I have defined a variable in form and I want to replace the value of empty session value with the value of variable defined in form. plz help

anees
Apr 3 '10 #1
Share this Question
Share on Google+
1 Reply


Atli
Expert 5K+
P: 5,058
Hey.

You simply set the appropriate element in the $_SESSION array to the value retrieved from the $_POST array.

All variables submitted through a form are put into the $_POST array (or the $_GET array, if you did not use the "post" method on the form). Then, to set the session, you just have to start the session and set the appropriate element.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. session_start();
  3. $_SESSION['myElement'] = $_POST['myFormVariable'];
  4. ?>
(You may want to look into input validation, to ensure the security of your application.)
Apr 5 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.