- <!DOCTYPE html>
- <html>
- <body>
- <h1>學生成績</h1>
- <?php
- $array = [ "Alice" => 85, "Bob" => 92, "Charlie" => 78, "David" => 88, "Eva" => 95 ];
- if(isset($_POST["name"]) && isset($_POST["score"]))
- {
- $student=$_POST["name"];
- $newscore=$_POST["score"];
- $array[$student]=$newscore;
- }
- echo '<table border=1>';
- echo '<tr><th>姓名</th><th>分數</th></tr>';
- foreach($array as $name=>$score)
- {
- echo '<tr><td>'.$name.'</td><td>'.$score.'</td></tr>';
- }
- echo'</table>'
- ?>
- <h1>更新學生成績</h1>
- <form method="post" action="practice3.php">
- <label>姓名: </label>
- <input type="text" name="name"><br>
- <label>成績: </label>
- <input type="nuber" name="score"><br>
- <input type="submit">
- </form>
- </body>
- </html>
複製代碼 |