dounuo1881 2016-02-20 15:03
浏览 25

在PHP中指示必填字段

I'm trying to create a PHP file of a process form that indicates the required fields when processed. The code that I have is:

<html>
    <head>
        <style type="text/css">
            .error{color: #FF0000;}
        </style>
    </head>
    <body>
    <?php
    if(isset($_POST['fullname']) && $_POST['fullname'] != "") {
        $fullname = $_POST['fullname'];
    }
    if(isset($_POST['email']) && $_POST['email'] != "") {
        $email = $_POST['email'];
    }
    if(isset($_POST['feedback']) && $_POST['feedback'] != "") {
        $text= $_POST['feedback'];
    }

    $nameErr = $emailErr = "";
    $name = $email = "";

    if ($_SERVER["REQUEST_METHOD"] == POST) {
        if (empty($_POST["fullname"])){
            $nameErr = "Name is required";
        } else {
            $name = test_input($_POST["fullname"]);
        }
        if (empty($_POST["email"])) {
            $emailErr = "Email is required";
        } else {
            $email = test_input($_POST["email"]);
        }
    }
    ?>
        <h1>Customer Feedback</h1>
        <p1>Please tell us what you think</p1><br><br>
        <form method='POST' action='<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>' >
            <p1>Your name:</p1><br>
            <input type="text" name="fullname" value="<?php echo $fullname; ?>"><br><br>
            <p1>Your email address:</p1><br>
            <input type="text" name="email" value="<?php echo $email; ?>"><br><br>
            <p1>Your feedback:</p1><br>
            <textarea rows="5"  cols="50" name="feedback"><?php echo $text;?></textarea><br><br>
            <input type="submit" Value="Send Feedback"><br><br>
            <?php
                error_reporting(E_ALL);


                $name = $_POST['fullname'];
                $email = $_POST['email'];
                $feed = $_POST['feedback'];

                if (empty($name)) 
                {
                    echo "Please enter your name, email and feedback.";
                }
                if (empty($email)) 
                {
                    echo "Please enter your email and feedback.";
                }
                if (empty($feed))
                {
                    echo "Please enter feedback.";
                }
                if (!empty($name) && !empty($email) && !empty($feed))
                {
                    echo "You have inserted the correct data";
                }
            ?>
        </form>
    </body>
</html>

However, when I run it on Chrome, I got a server error 500 saying that

The website encountered and error while retrieving process_4.php. It maybe down for maintenance or configured incorrectly.

The other PHP files that I've made leading up to this point have all worked correctly and I don't know why this one isn't.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
    • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
    • ¥15 划分vlan后,链路不通了?
    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
    • ¥15 个人网站被恶意大量访问,怎么办
    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 Centos / PETGEM
    • ¥15 划分vlan后不通了
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)