各位大神,
我做了一个简单的注册页面,里面有验证用户名格式,生日格式等等,这些都没问题。
问题在我输入姓和名之后  返回页面一直提示我没输入姓和名 这是为什么??
就是说 我在这个注册页面每一个文本框都填了,最后提示我first name和last name是空白的,为什么啊?????
主要代码如下:<div id="main">
<div id="banner">
</div>
<div id="container">


<?php
$username_label = "has to be a email address. e.g. [email protected]";
$username_error_color="#c0c0c0";

$password_label="";
$password_error_color="#c0c0c0";

$reEnter_psw_label="";
$reEnter_psw_error_color="#c0c0c0";

$fName_label="This will be appearing on the invoice";
$fName_error_color="#c0c0c0";

$lName_label="This will be appearing on the invoice";
$lName_error_color="#c0c0c0";

$mobile_label="This is used to confirm with buyer in case of pay cash on delivery.";
$mobile_error_color="#c0c0c0";

$DOB_label="Optional field, formate: dd/mm/yyyy";
$DOB_error_color="#c0c0c0";

if(isset($_POST['btn_login'])&&$_POST['btn_login'] == 'Login')
{
header("Location:login.php");
} if(isset($_POST['btn_register'])&&$_POST['btn_register'] == 'Register')
{
$username=$_POST['username'];
$password=$_POST['password'];
$reEnter_psw=$_POST['re_enter'];
$fname=$_POST['txt_fname'];
$lname=$_POST['txt_lname'];
$type="member";
$mobile=$_POST['txt_mobile'];
$suburb_id=$_POST['suburb_select'];
$gender=$_POST['gender'];
$DOB_str=$_POST['txt_DOB'];

$canRegister=true;
$err_msg="no err";
if($username==""){$username_label="you need to input a username(email address)."; $username_error_color="red"; $canRegister=false;$err_msg="err: username empty";}
if($password==""){$password_label="you need to input a password."; $password_error_color="red"; $canRegister=false; $err_msg="err: password empty";}
if($reEnter_psw==""){$reEnter_psw_label="you need to re-enter the same password."; $reEnter_psw_error_color="red"; $canRegister=false; $err_msg="err: re_enter incorrect";}
if($fName==""){$fName_label="you need to provide your first name."; $fname_error_color="red"; $canRegister=false; $err_msg="err: fName empty";}
if($lName==""){$lName_label="you need to provide your last name."; $lname_error_color="red"; $canRegister=false; $err_msg="err: lname empty";}
if($mobile==""){$mobile_label="mobile is neccessary for confirmation."; $mobile_error_color="red"; $canRegister=false;$err_msg="err: mobile empty";}


if($username!="")
{
//filter for email validation
//reference: www.w3school.com
if(!filter_var($username, FILTER_VALIDATE_EMAIL))
{
$username_label="please input a email as your username, e.g. [email protected]";
$username_error_color="red";
$err_msg="err: email format";
$canRegister=false;
}
else
{
$query="SELECT * FROM USERS WHERE username='$username'";
$result=queryMysql($query);
$rows=mysql_num_rows($result);
if($rows == 1)
{
$username_label="the email has already existed.";
$username_error_color="red";
$err_msg="err: email already existed";
$canRegister=false;
}
}
}

if($password != $reEnter_psw)
{
$reEnter_psw_label="the re-entered password is not same.";
$reEnter_psw_error_color="red";
$err_msg="err: password incorrect";
$canRegister=false;
}

if($DOB_str != "")
{
list($day, $month, $year)=split('/', $DOB_str);
if(!checkdate($month, $day, $year))
{
$DOB_label="invalid date! e.g. format dd/mm/yyyy";
$DOB_error_color="red";
$err_msg="err: date format incorrect";
$canRegister=false;
}

}
if($canRegister)
{
$query="SELECT str_to_date('$DOB_str', '%d/%m/%Y') AS Formated_DOB";
$result=queryMysql($query);
//echo "result str__to_date successful";
if($result)
{
$get_dob=mysql_fetch_array($result);
$DOB=$get_dob['Formated_DOB'];
$query="INSERT INTO USERS (
username, 
psw, 
type, 
fName, 
lName, 
DOB, 
gender, 
suburb_id, 
mobile) 
VALUES (
'$username', 
'$password', 
'$type', 
'$fname', 
'$lname', 
'$DOB', 
'$gender', 
'$suburb_id', 
'$mobile' )";
$result=queryMysql($query);
//echo "result insert successful";

if(result)
{
echo "login successful";
$_SESSION['user']=$username;
$_SEESION['type']="member";
header("Location:index.php");
}
}
}
}

?>


<table border="0px" id="member_action" style="margin-left:auto; margin-right: auto; margin-top: 70px; margin-bottom: 70px; font-family: Verdana, Arial, Helvetica, sans-serif;">
<tr>
<th colspan=2 style="font-size: 20pt; color: #4a8cf6">Register a Member</th>
</tr>
<tr>
<td colspan=2 style="font-size: 9.5pt; color: red" id="error_msg"><?php echo $err_msg; ?></td>
</tr>



<form name="register_form" method="post" action="register.php">

<tr>
<td style="font-size: 10.5pt">Username:</td>
<td style="color:red"><input class="textbox" type="text" name="username" /></td>
<td style="font-size: 7.5pt; color: <?php echo $username_error_color; ?>"><font color="red">*</font> <?php echo $username_label; ?></td>
</tr>

<tr>
<td style="font-size: 10.5pt">Password: </td>
<td style="color:red"><input class="textbox" type="password" name="password" /></td>
<td style="font-size: 7.5pt; color: <?php echo $password_error_color; ?>"><font color="red">*</font> <?php echo $password_label; ?></td>
</tr>

<tr>
<td style="font-size: 10.5pt">Re-Enter: </td>
<td style="color:red"><input class="textbox" type="password" name="re_enter" /></td>
<td style="font-size: 7.5pt; color: <?php echo $reEnter_psw_error_color; ?>"><font color="red">*</font> <?php echo $reEnter_psw_label; ?></td>
</tr>

<tr>
<td style="font-size: 10.5pt">First Name: </td>
<td style="color:red"><input class="textbox" type="text" name="txt_fname" /></td>
<td style="font-size: 7.5pt; color: <?php echo $fName_error_color; ?>"><font color="red">*</font> <?php echo $fName_label; ?></td>
</tr>

<tr>
<td style="font-size: 10.5pt">Last Name: </td>
<td style="color:red"><input class="textbox" type="text" name="txt_lname" /></td>
<td style="font-size: 7.5pt; color: <?php echo $lName_error_color; ?>"><font color="red">*</font> <?php echo $lName_label; ?></td>
</tr>

<tr>
<td style="font-size: 10.5pt">Mobile: </td>
<td style="color:red"><input class="textbox" type="text" name="txt_mobile" /></td>
<td style="font-size: 7.5pt; color: <?php echo $mobile_error_color; ?>"><font color="red">*</font> <?php echo $mobile_label; ?></td>
</tr>

<tr>
<td style="font-size: 10.5pt">Living in: </td>
<td>
<?php
$query="SELECT * FROM SUBURBS";
$result=queryMysql($query);
echo "<select name='suburb_select'>";
while($get_suburb=mysql_fetch_array($result))
{
$suburb_id=$get_suburb['suburb_id'];
$suburb_name=$get_suburb['suburb_name'];

echo "<option value='$suburb_id'>$suburb_name</option>";
}
echo "</select>";
?>
</td>
<td style="font-size: 7.5pt; color: #c0c0c0">Optional field</td>
</tr>

<tr>
<td style="font-size: 10.5pt">Gender: </td>
<td style="font-size: 10.5pt">
<input class="radio_box" type="radio" name="gender" value="Male"/>Male
<input class="radio_box" type="radio" name="gender" value="Female"/>Female
</td>
<td style="font-size: 7.5pt; color: #c0c0c0">Optional field</td>
</tr>

<tr>
<td style="font-size: 10.5pt">Date of Birth: </td>
<td><input class="textbox" type="text" name="txt_DOB" /></td>
<td style="font-size: 7.5pt; color: <?php echo $DOB_error_color; ?>"><?php echo $DOB_label; ?></td>
</tr>

<tr>
<td style="font-size: 10.5pt"></td>
<td style="font-size: 7.5pt; color: red">*: required fields</td>
</tr>

<tr>
<td style="font-size: 10.5pt"></td>
<td style="font-size: 7.5pt; color: red">please fill the optional fields for <br />helping us to improve.</td>
</tr>

<tr>
<td></td>
<td>
<input style="float: left" class="button" type="submit" name="btn_login" value="Login" />
<input style="float: right; margin-right: 10px" class="button" type="submit" name="btn_register" value="Register" />
</td>
</tr>

</form>
</table>
</div>