How can new columns be generated from calculations based on input fields in a PHP form?
To generate new columns from calculations based on input fields in a PHP form, you can retrieve the input values using $_POST, perform the necessary calculations, and then display the results in new columns in the form.
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$num1 = $_POST['num1'];
$num2 = $_POST['num2'];
$sum = $num1 + $num2;
$product = $num1 * $num2;
echo "<table border='1'>";
echo "<tr><th>Number 1</th><th>Number 2</th><th>Sum</th><th>Product</th></tr>";
echo "<tr><td>$num1</td><td>$num2</td><td>$sum</td><td>$product</td></tr>";
echo "</table>";
}
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
Number 1: <input type="text" name="num1"><br>
Number 2: <input type="text" name="num2"><br>
<input type="submit" value="Calculate">
</form>