I have 2 forms on my page and I want only the variables from the form that was submited to be passed on. I have to store the variables in $var format. What I want to do is to delete the variables from the form that was not submited and pass the variables from the form that was submited to the next page. So... How do you pass specific variables from one page to another and/or delete specific variables? Thanks in advance! ~imozeb
To delete a variable use unset(), or you can overwrite a variable by recalling it except making it do, something else. To pass it on to another page use $_REQUEST (or $_POST or $_GET, depending on the form type).
You can pass variable from one page to another by, 1. SESSION variable; 2. by cookie; 3. storing variable in database (use when security is absolute priority).
Okay. I tried to use the PHP session command and it gave me an error "session does not exist so cant be destroyed". Why? I programmed it like this. page1.php: $username = "Mr World"; session_start(); $_SESSION['username'] = $username; //then redirect to page2.php page2.php: if isset($_SESSION['username']) { $username = $_SESSION['username']; } session_destroy(); echo $username;
have to restart the session on page2 that will get rid of the error you listed. page2.php: session_start(); if isset($_SESSION['username']) { $username = $_SESSION['username']; } session_destroy(); echo $username; http://www.tizag.com/phpT/phpsessions.php
You can use cookie too. It is simple and useful. page1.php setcookie('username',$username); PHP: page2.php if isset($_COOKIE['username']){$username = $_Cookie['username'];} PHP: