How can data be passed from one page to another using $_POST in PHP?
To pass data from one page to another using $_POST in PHP, you can submit a form with method="post" and then access the data on the receiving page using the $_POST superglobal array. Simply set the form action attribute to the URL of the receiving page.
// Sending page (form submission)
<form method="post" action="receiver.php">
<input type="text" name="data">
<button type="submit">Submit</button>
</form>
// Receiving page (receiver.php)
<?php
if(isset($_POST['data'])){
$receivedData = $_POST['data'];
echo "Received data: " . $receivedData;
}
?>
Keywords
Related Questions
- What are the potential pitfalls of using PHP to add files to a zip archive or unpack them?
- What are some best practices for efficiently handling and processing log files in PHP to avoid performance issues and memory consumption?
- How can PHP be used to compare arrays and identify differences in values?