There are a page page1.php below:-
JavaScript
x
<?php
$name = "xyz";
?>
<form action="page2.php" method="POST">
Age : <input type="number" name="age">
<button type="submit">SUBMIT</button>
</form>
after submitting the form at page1, How to get value of $name of page1.php in page2.php what should change in page-1?
Advertisement
Answer
If you ask also for a name on page1, then simply use another input:
JavaScript
<form action="page2.php" method="POST">
Name : <input type="text" name="name">
Age : <input type="number" name="age">
<button type="submit">SUBMIT</button>
</form>
If the name is fixed and you want it transmitted via POST, usa a hidden input:
JavaScript
<form action="page2.php" method="POST">
Name : <input type="hidden" name="name" value="<?php echo htmlspecialchars($name) ?>">
Age : <input type="number" name="age">
<button type="submit">SUBMIT</button>
</form>
Then in page2.php read the POST-ed value:
JavaScript
$name = $_POST['name'];