I have 3 files. I will give you the exact example:
a.php
<form action="b.php" method="POST">
Enter age:
<input type="text" name="age"><br>
<input type="submit" value="Save">
</form>
b.php
<?php
$age=$_POST["age"];
if (is_numeric($age))
{
header("Location: c.php");
exit();
}
else
{
echo "Age invalid!";
}
?>
c.php
<?php
//i want to use the $age variable here
echo $age;
?>
How can I use the $age variable from b.php in c.php?
I also tried to session_start(); at file b.php and use $_SESSION["age"]=$_POST["age"]; in b.php and then $_SESSION["age"] in c.php in stead of $age and it still didn't work.
I also tried include but didn't get me anywhere either... maybe I didn't use it correctly.
The issue is that in file b.php, you are not sending the value of age to c.php.
If, in b.php, you did this:
session_start();
$_SESSION["age"] = $_POST["age"];
Then, in c.php, you did this:
session_start();
$age = $_SESSION["age"];
echo $age;
It will work properly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With