首页 >> 科技 >>默认分类 >> 使用一个隐藏字段保存状态-网站建设
详细内容

使用一个隐藏字段保存状态-网站建设

使用一个隐藏字段保存状态-网站建设

1: <?php

2: $num_to_guess = 42;

3: $num_tries = (isset($_POST['numJnes'])) ? $num_tries +1:1;

4: if (!isset($_POST['guess'])) {

5: $message = "Welcome to the guessing machine!”;

6:} elseif (!is_numeric($_POST['guess'])) {// is not numeric

7: $message = "I don't understand that response.";

8:} elseif ($_POST['guess'] == $num_to__guess) {// matches!

9: $message = 'Well done!";

10:} elseif ($_POST['guess'] > $num_to_guess) {

11: $message = $_POST['guess']." is too big! Try a smaller number.";

12:} elseif ($_POST['guess'] < $num_to__guess) {

13: $message = $_POST['guess'].,^ is too small! Try a larger number.";

14:} else {// some other condition

15: $message = "I am terribly con fused.";

16:}

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

?>

<!DOCTYPE html>

<html lang=“e

<head>

<title>A PHP number guessing script</title>

</head>

<body>

<h1><?php echo $message; ?></h1>

<p><strong>Guess number:</strongx?php echo $numjries; ?></p>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method=Hpos <p><label for="guess">Type your guess here:</label><br> vinput type="textn id="guess" name="guess"></p>

vinput type="hidden" name="num_tries" value=H<?php echo $num_tri« <button type=,,submitn name="submit" value=nsubmit">Submit</buttor </form>

</body>

</html>

将上述代码保存为numguess2.php文件并且将其放置到Web服务

器文档的根目录下。使用Web浏览器访问表单几次,并且尝试猜这个 数字(假装你还并不知道它)。每次访问表单,计数器将会増加仁


  • 电话直呼

    • 18659300341
    • 在线客服 :
    • 在线客服 :
  • 微信客服

技术支持: 厦门茗菲苑信息科技有限公司 | 管理登录
0
×

购物车

商品名称 数量 产品单价 折扣 总计
金额总计:¥23立即结算