0

名前、性別、または寮がユーザーによって送信されない場合、ページは「登録」ボタンを押すと赤色でエラーを表示するはずです。これは私のコードですが、うまく機能していません。その常にユーザーにエラーを与えています。

<?php 
//checking if submitted

if(isset($_POST["action"]))
{
    if (empty($_POST["name"]) || empty($_POST["gender"]) || empty($_POST["dorm"]))
        $error=true;
}
?>

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Fresh IMs</title>
    </head>
    <body>
        <div style="text-align:center">
            <h1>Register for Fresh IMs</h1>
            <br/><br/>
            <? if(isset($error)): ?>
                <div style="color:red"> You must fill out the form!</div>
            <? endif ?>
            <form action="index.php" method="post">
                <table style="border:0; margin-left:auto; margin-right:auto">
                    <tr>
                        <td>Name:</td>
                        <td><input name="name" type="text"></td>
                    </tr>
                    <tr>
                        <td>Captain:</td>
                        <td><input name="captain" type="checkbox"></td>
                    </tr>
                    <tr>
                        <td>Gender:</td>
                        <td>
                            <input name="gender" type="radio" value="F">F
                            <input name="gender" type="radio" value="M">M
                        </td>                       
                    </tr>
                    <tr>
                        <td>Dorm:</td>
                        <td>
                            <select name="dorm">
                                <option value="" ></option>
                                <option value="Apply court" >Apply Court</option>
                                <option value="Candy">Candy</option>
                            </select>
                        </td>
                    </tr>
                </table>
                <input name="action" type="submit" value="Register">
            </form> 
        </div>
    </body>
</html>
4

2 に答える 2

0

empty関数でisset関数を変更してみてください

于 2013-10-05T05:46:11.867 に答える
0

The Problem is should this one You Missed thephp tag

<?php if (isset($error)): ?>
                <div style="color:red"> You must fill out the form!</div>
                <?php endif ?>

これを試してみてください

ありがとう

于 2013-10-05T05:54:44.157 に答える