How can PHP be used to create a table with interactive features like adding data through buttons?
To create a table with interactive features like adding data through buttons using PHP, you can use HTML forms to collect user input and PHP to handle the data submission. When the form is submitted, PHP can process the input and update the table accordingly. You can use PHP to dynamically generate the table based on the data stored in a database or an array.
<?php
// Check if form is submitted
if(isset($_POST['submit'])){
// Get input data from the form
$newData = $_POST['new_data'];
// Add the new data to the table (you can store it in a database or array)
// For example, if using an array:
$data[] = $newData;
// Display the updated table
echo '<table>';
foreach($data as $row){
echo '<tr><td>'.$row.'</td></tr>';
}
echo '</table>';
}
?>
<!-- HTML form to add new data -->
<form method="post" action="">
<input type="text" name="new_data" placeholder="Enter new data">
<input type="submit" name="submit" value="Add Data">
</form>