PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Hi... I have a couple of
1/ If I create a variable in file1.php and this one call file2.php, is the variable still declared in the 2nd file?
2/ What function can I use to call another homepage?
Warning: Cannot modify header information - headers already sent by (output started at /home/blahblah/public_html/loaners/addLP.php:6) in /home/blahblah/public_html/loaners/addLP.php on line 46
<?php
// Updating variables
$LPIN = htmlspecialchars($_POST['LPIN']);
$ESN = htmlspecialchars($_POST['ESN']);
$Model = htmlspecialchars($_POST['Model']);
$Store = htmlspecialchars($_POST['Store']);
echo "$error_input"; /* Just testing if my variable was "20" */
$error_input=0;
if (strlen($ESN)!=11) $error_input=1;
if ($Store=="Select one") $error_input=2;
Switch($error_input)
{
case 1: $error_message = 'ESN must have 11 characters.'; break;
case 2: $error_message = 'Select a store.'; break;
}
header("location: http://www.gophp5.org"); /* I would like to come back to the previous file if my conditions are not fulfill */
?>
You're posting to that page. PHP is stateless, it has no knowledge of previous requests. If you wish to carry information from one page to another you need to communicate it. This needs to be done via posting, url, cookies, or sessions.
No the variable wouldn't be passed like that. If you had 'include' a second PHP file the variable is available.
The easiest way is to add a hidden field to your form with the value you want to pass: