朋友我需要你的帮助..表单验证工作正常...但是表单没有将值提交到数据库这里是表单
<form action="submit.php" method="post" id="regForm">
<input id="fname" placeholder="First name" type="text" name="fname" />
<input id="lname" placeholder="Last name" type="text" name="lname" />
<input id="email" placeholder="E-mail" type="text" name="email" />
<input id="email" placeholder="Password" type="password" name="pass"/>
<div id="email">Birthday<input id="dat" type="text" placeholder="DD" name="day" maxlength="2" onkeypress="return yr(event)"/>/<input id="dat" type="text" maxlength="2" placeholder="MM" name="month" onkeypress="return yr(event)"/>/<input id="dat" maxlength="4" type="text" placeholder="YYYY" name="year" onkeypress="return yr(event)"/>
</div>
<div class="radio"><input type="radio" name="sex" value="Male">Male</input></div><div class="radio"><input type="radio" name="sex" value="Female">Female</input></div><div class="radiol"><input type="radio" name="sex" value="Others">Others</input></div>
<input id="reg1" type="submit" value="Register" name="reg" />
</form>
submit.php 中的验证代码工作正常但表单提交的代码根本不工作.. submit.php
<?php $con=mysql_connect('localhost','root','');
if(!$con)
{
die('could not connect'.mysql_error());
}
mysql_select_db("test",$con);
// declared variables
$fn=$_POST['fname'];
$ln=$_POST['lname'];
$em=$_POST['email'];
$pswd=$_POST['pass'];
$date=new DateTime($_POST['year'].'-'.$_POST['month'].'-'.$_POST['day']);
$sex=$_POST['sex'];
// we check if everything is filled in
if(empty($fn) || empty($ln) || empty($em) || empty($pswd))
{
die(msg(0,"All the fields are required"));
}
// is the birthday selected?
if (!@checkdate($_POST['month'],$_POST['day'],$_POST['year'])) {
die(msg(0,"Please fill correct birthday"));
}
// is the sex selected?
if(!$sex)
{
die(msg(0,"Please select your gender"));
}
// is the email valid?
if(!(preg_match("/^[\.A-z0-9_\-\+]+[@][A-z0-9_\-]+([.][A-z0-9_\-]+)+[A-z]{1,4}$/", $_POST['email'])))
{die(msg(0,"You haven't provided a valid email"));}
//Check whether Email already exists in the database
$e_check = mysql_query("SELECT email FROM registeration WHERE email='$em'");
//Count the number of rows returned
$email_check = mysql_num_rows($e_check);
if($email_check > 0){die(msg(0,"This email is already used"));}
// check the maximum length of password
if (strlen($pswd)<5) {die(msg(0,"Please provide a longer password"));}
//encrypt password and password 2 using md5 before sending to database
$pswd = md5($pswd);
$qu = mysql_query("INSERT INTO registeration (id,fname,lname,email,password,birthday,sex,activated) VALUES ('','$fn','$ln','$em','$pswd','$date','$sex','0')");
if(!$qu) {
die('could not connect'.mysql_error());
}
echo msg(1,"registered.html");
function msg($status,$txt)
{
return '{"status":'.$status.',"txt":"'.$txt.'"}';
}
?>
成功提交表单后,用户应该被重定向到registered.html,但它停留在同一页面上