PHP

PHP $_POST

2020-04-23  本文已影响0人  887d1fc86fe6
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<?php
// 以防首次进来在 html 中使用对象报错未定义
$num2 = '';
$num2 = '';
$result = '';
// 程序默认是从上到下,首次进来会直接执行这段代码,所以需要检查是否有值
if (isset($_POST['num1'])) {
  $num1 = $_POST['num1'];
  $num2 = $_POST['num2'];
  $result = $num1 + $num2;
}
?>

<body>
  <!-- action 留空就标识提交给自己(本页) -->
  <form action="" method="post">
    <input type="text" name="num1" value="<?php echo $num1 ?>">
    +
    <input type="text" name="num2" value="<?php echo $num2 ?>">
    <input type="submit" value="=">
    <input type="text" name="result" value="<?php echo $result ?>">
  </form>
</body>
</html>
上一篇 下一篇

猜你喜欢

热点阅读