程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> php-初學PHP,這段測試代碼的初始化錯在哪兒?怎麼改?

php-初學PHP,這段測試代碼的初始化錯在哪兒?怎麼改?

編輯:編程綜合問答
初學PHP,這段測試代碼的初始化錯在哪兒?怎麼改?
<?php
    $number_to_guess = 42;
    $num_tries = (isset($_POST['num_tries']))? $num_tries+1:1;
    if(!isset($_POST['guess']))
        $message = "Welcome to the guessing machine!";
    elseif(!is_numeric($_POST['guess']))
        $message = "Not a num!";
    else if($_POST['guess'] == $number_to_guess)
        $message = "Well Done!";
    else if($_POST['guess'] > $number_to_guess)
        $message = $_POST['guess']." is too big, Try a smaller one!";
    else if($_POST['guess'] < $number_to_guess)
        $message = $_POST['guess']." is too small, Try a bigger one!";
    else
        $message = "I am terribly confused!";
    echo $_SERVER['PHP_SELF'];
?>
<!DOCTYPE html>
<html>
    <head>
        <title>A HTML/PHP that calls itself!</title>
    </head>
    <body>
    <h1>
        <?php
            echo "Guessing Result:<br/>\"".$message."\"";
        ?>
    </h1>
    <p><strong>Guess number:</strong>
    <?php
        echo $num_tries;
    ?>
    </p>
    <form method="post" action="
    <?php
        echo $_SERVER['PHP_SELF'];
    ?>
    ">
        <p><label for="guess">Type your guess here:</label><br/>
        <input type="text" id="guess" name="guess"/></p>
        <input type="hidden" name="num_tries" value="
        <?php
            echo $num_tries;
        ?>" /></p>
        <button type="submit" name="submit" value="send">Guess it!</button>
    </form>
    </body>
</html>  

圖片說明

最佳回答:


把isset改成empty試一下。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved