PHP表格选择&无线电错误

时间:2012-12-05 08:57:17

标签: php

PHP表单选择&无线电错误 我有一个表单,但我在选择按钮和单选按钮上出现php错误 我得到的错误是$ age和$ gender

如何在同一页面中打印错误信息?

这里是php代码

$firstname="";  $lastname="";   $email="";  $re_email="";

if(isset($_POST['register'])){
    $firstname=strip_tags($_POST['firstname']);
    $lastname=strip_tags($_POST['lastname']);
    $email=strip_tags(strtolower($_POST['email']));
    $re_email=strip_tags(strtolower($_POST['re_email']));
    $password=strip_tags($_POST['password']);
    $re_password=strip_tags($_POST['re_password']);
    $age=$_POST['age'];
    $gender=$_POST['gender'];
    $date=date("Y-m-d");

    if($firstname && $lastname && $email && $re_email && $password && $re_password && $age && $gender){}
    else{die("Please fill in all fields");}

    //USERNAME CHECKING//////////////////////////////////////////////////////////////////
    $connect=mysql_connect("localhost", "root", "");
    $database=mysql_select_db("phplogin", $connect);
    $namecheck=mysql_query("SELECT email FROM users WHERE email='$email'");
    $count=mysql_num_rows($namecheck);
    if($count!=0)
    {die("Username already taken");}

这里是Html代码

<html>
<H1>Register</H1>
    <form action="register.php" method="POST">
    <table>
        <tr>
            <td>First Name:</td>
            <td><input type="text" name="firstname" value="<?PHP echo $firstname;?>" maxlength="25"/></td>
            <td>Maxium 25 characters</td>
        </tr>

        <tr>
            <td>Last Name:</td>
            <td><input type="text" name="lastname" value="<?PHP echo $lastname;?>"maxlength="25"/></td>
            <td>Maxium 25 characters</td>
        </tr>

        <tr>
            <td>email:</td>
            <td><input type="text" name="email" value="<?PHP echo $email;?>"maxlength="40"/></td>
            <td>Maxium 40 characters</td>
        </tr>

        <tr>
            <td>Re-enter email:</td>
            <td><input type="text" name="re_email" value="<?PHP echo $re_email;?>"maxlength="40"/></td>
        </tr>

        <tr>
            <td>Password:</td>
            <td><input type="password" name="password" maxlength="25"/></td>
            <td>Password must be between 6 and 25 characters</td>
        </tr>

        <tr>
            <td>Re-eneter Password:</td>
            <td><input type="password" name="re_password" maxlength="50"/></td>
        </tr>
    </table>
    <select>
            <option value="">Age</option>
            <option name="age" value="18-29">18-29</option>
            <option name="age" value="30-39">30-39</option>
            <option name="age" value="40-49">40-49</option>
            <option name="age" value="50-59">50-59</option>
            <option name="age" value="60-69">60-69</option>
            <option name="age" value="70">70 Plus</option>
        </select>
        <input type="radio" name="gender" value="male" />Male
        <input type="radio" name="gender" value="female" />Female
    <input type="submit" name="register" value="Register" />
    </form>
</html>

3 个答案:

答案 0 :(得分:0)

将register.php中的代码放在表单下面 并将表单操作设置为同一页面, 那么你将能够在同一页面上显示错误

 <form action="<?php echo $_SERVER['PHP_SELF'] ?>"

答案 1 :(得分:0)

要启用错误报告,请添加到您的页面:

ini_set('display_errors',1); 
error_reporting(E_ALL);

要允许向所有页面报告错误,请添加到php.ini:

error_reporting  =  E_ALL
display_errors = On

并重新启动Apache服务。

将玩具选择更改为:

<select name="age">
     <option value="18-29">18-29</option>
     <option value="30-39">30-39</option>
     <option value="40-49">40-49</option>
     <option value="50-59">50-59</option>
     <option value="60-69">60-69</option>
     <option value="70">70 Plus</option>
 </select>

答案 2 :(得分:0)

首先在您的HTML中,对于SELECT,您需要在SELECT上设置“name”,而不是在OPTIONS上。