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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • arsha123
    New Member
    • Apr 2010
    • 1

    #1

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

    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
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    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.

    [code=php]<?php
    session_start() ;
    $_SESSION['myElement'] = $_POST['myFormVariable '];
    ?>[/code]
    (You may want to look into input validation, to ensure the security of your application.)

    Comment

    Working...