douyo770657 2016-02-10 17:53
浏览 23
已采纳

这些PHP功能是否正确? [关闭]

I just want to know if this piece of code is correct, because for some reason it's not working for me and I don't know why. If you need me to tell you additional information about my problem or my system just ask for it!

<?php
    function add($x,$y) {
        $result= $x+$y;
        return $result;
    };

    $number1= $_POST['n_1'];
    $number2= $_POST['n_2'];
    echo $number1.“ + ".$number2." = ".add($number1,$number2);

    for ($i=5;$i<=50;$i+=5) {
        echo $i."</br>";
    };

    $j=10;
    while ($j>0){
        echo $j.“</br>";
        $j--;
    };
>

<!DOCTYPE html>
<html>
    <head>
    </head>
    <body>
        <form action=“thisfile.php" method="POST">
            <label for="fullname">Full name: </label>
            <input type="text" name="fullname" size="20"></br>
            <label for="data">Data: </label>
            <textarea rows="5" name="data" cols="20"></textarea></br>
            <label for="valid">Valid?: </label>
            <input type="checkbox" name="valid" value="ON"></br>
            <label for="color">Color: </label>
            <input type="radio" value="blue" checked name="color">Blue
            <input type="radio" value="red" checked name="color">Red</br>
            <label for="month">Month: </label>
            <select size="1" name="month">
                <option selected value="january">January</option> 
                <option value="february">February</option>
                <option value="march">March</option>
            </select></br>
            <label for="n_1">Number 1: </label>
            <input type="text" name="n_1" size="20"></br>
            <label for="n_2">Number 2: </label>
            <input type="text" name="n_2" size="20"></br>
            <input type="submit" value="send" name="send">
        </form>
    </body>
</html>

Thanks!

  • 写回答

2条回答 默认 最新

  • douwu5009 2016-02-10 18:03
    关注

    Please check the below code, what wrong you did are commented in code:-

    <?php
    error_reporting(E_ALL); // check all error including warning and notice error too
    ini_set('display_errors',1); // display errors
        function add($x,$y) {
            $result= $x+$y;
            return $result;
        } // ; not needed
    
        $number1= $_POST['n_1'];
        $number2= $_POST['n_2'];
        echo $number1." + ".$number2." = ".add($number1,$number2);// using “ is wrong
    
        for ($i=5;$i<=50;$i+=5) {
            echo $i."</br>";
        } // ; not needed
    
        $j=10;
        while ($j>0){
            echo $j."</br>"; // using “ is wrong
            $j--;
        }//; not needed
    ?> <!-- closing  error-->
    
    <!DOCTYPE html>
    <html>
        <head>
        </head>
        <body>
            <form action="thisfile.php" method="POST"> <!--// using “ is wrong -->
                <label for="fullname">Full name: </label>
                <input type="text" name="fullname" size="20"></br>
                <label for="data">Data: </label>
                <textarea rows="5" name="data" cols="20"></textarea></br>
                <label for="valid">Valid?: </label>
                <input type="checkbox" name="valid" value="ON"></br>
                <label for="color">Color: </label>
                <input type="radio" value="blue" checked name="color">Blue
                <input type="radio" value="red" checked name="color">Red</br>
                <label for="month">Month: </label>
                <select size="1" name="month">
                    <option selected value="january">January</option> 
                    <option value="february">February</option>
                    <option value="march">March</option>
                </select></br>
                <label for="n_1">Number 1: </label>
                <input type="text" name="n_1" size="20"></br>
                <label for="n_2">Number 2: </label>
                <input type="text" name="n_2" size="20"></br>
                <input type="submit" value="send" name="send">
            </form>
        </body>
    </html>
    

    Note:- applying POST data checks (validation) is your responsibility, add them too along with the code. Thanks

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 表达式必须是可修改的左值
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题