<form action="process.php" method="post"> <label for="name">姓名:</label> <input type="text" name="name" id="name"> <input type="submit" value="提交"> </form>
<?php if($_POST['name']) { $name = $_POST['name']; echo "你好," . $name . "!"; } ?>
<form action="process.php" method="post"> <label for="fruits">选择水果:</label> <input type="checkbox" name="fruits[]" value="apple">苹果 <input type="checkbox" name="fruits[]" value="banana">香蕉 <input type="checkbox" name="fruits[]" value="orange">橙子 <input type="submit" value="提交"> </form>
<?php if(isset($_POST['fruits'])) { $selectedFruits = $_POST['fruits']; echo "你选择了以下水果:"; foreach($selectedFruits as $fruit) { echo $fruit . " "; } } ?>