Demonstrates how to submit and retrieve form data using the GET method.
echo "<h3?>
Welcome, " . $userName . "!"; echo "You are a " . ($gender === 'male' ? 'boy' : 'girl') . "!"; } ?> Experiment 2: Handling Form Data with POST Method
Demonstrates how to submit and retrieve form data using the POST method.
Your Name:
Gender: Male Female
Occupation: Student Teacher Doctor
Highest Education: Middle School High School Bachelor Master or Above
Your Comments:
<?php // This would be in process_post.php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$feedbackName = htmlspecialchars($_POST['feedbackName']);
$gender = $_POST['gender'];
$occupation = $_POST['occupation'];
$education = $_POST['education'];
$comments = htmlspecialchars($_POST['commments']);
echo "<h3?>
Thank you, " . $feedbackName . "!"; echo "Please confirm your information:
"; echo "Gender: " . $gender . "
"; echo "Occupation: " . $occupation . "
"; echo "Education: " . $education . "
"; echo "Comments: " . $comments . "
"; } ?> Experiment 3: Calculating Sum from 1 to N
Calculates the sum of numbers from 1 to a user-specifide number.
Calculate 1+2+3+...+ <?php if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['targetNumber'])) { $targetNumber = (int)$_POST['targetNumber']; $sum = 0;
if ($targetNumber ?>
- { for ($i = 1; $i <= $targetNumber; $i++) { $sum += $i; } echo "alert('The sum from 1 to " . $targetNumber . " is: " . $sum . "')"; } else { echo "alert('Please enter a positive number')"; } } ?>