php怎么编写验证控件阿
急需提交注册信息的验证
我有四个页面分别是eq.php,re.php,login.php和register1.php
eq.php内容是
<?
require_once('login.php');
$link = mysql_connect("localhost","root","");
mysql_select_db("php");
$username=$_POST['username'];
$password=$_POST['password'];
$exec="select * from user where username='".$username."'";
if($result=mysql_query($exec))
{
if($rs=mysql_fetch_object($result))
{
if($rs->password==$password)
{
echo "<script>alert('Login Successful!');location.href='login.php';</script>";
}
else
{
echo "<script>alert('Password Wrong!');location.href='login.php';</script>";
}
}
else
{
echo "<script>alert('Username No Exist!');location.href='login.php';</script>";
}
}
else
{
echo "<script>alert('Database Connection Failed!');location.href='login.php';</script>";
}
?>
re.php内容是
<?
require_once('register1.php');
$link = mysql_connect("localhost","root","");
mysql_select_db("php");
$username=$_POST['username'];
$password=$_POST['password'];
$email=$_POST['email'];
$exec="insert into user values ('','$username','$password','$email')";
$result=mysql_query($exec);
echo $result;
?>
login.php内容是
<form action="eq.php" method="post" >
<p>username:<input type="text" name="username" width=120/>
<p>password:<input type="password" name="password" width=120/>
<p> <input name="" type="submit" value="Enter" />
<input name="" type="button" value="Register" onclick="javascript:document.location.href='register1.php'"/></form>
register1.php内容是
<form action="re.php" method="post">
<p>username: <input type="text" name="username" width=120/>
<p>password: <input type="password" name="password" width=120/>
<p>repassword:<input type="password" name="repassword" width=120/>
<p>email: <input type="text" name="email" width=120/>
<p><input name="" type="submit" value="submit"/>
</form>
现在我想验证注册表单,就是说不等随便注册成功了我该怎么做。各位高手别笑话我实在不知道该如何问,我特急,快帮帮我吧。
参考答案:<script type="text/javascript">
function formSubmit(form) {
if(!form.username.value) {
alert('请输入用户名!');
form.username.focus();
return false;
}
if(!form.password.value) {
alert('请输入密码!');
form.password.focus();
return false;
}
if(!form.repassword.value) {
alert('请确认密码!');
form.repassword.focus();
return false;
}
if (form.password.value != form.repassword.value) {
alert('输入的密码不一致,请重新输入!');
form.repassword.value="";
form.repassword.focus();
return false;
}
if(!form.email.value) {
alert('请输入邮件地址!');
form.email.focus();
return false;
}else
{
var pattern = /([0-9a-zA-Z_-]+)@([0-9a-zA-Z_-]+)\.([0-9a-zA-Z_-]+)/;
if (!pattern.test(form.email.value))
{
alert('输入正确的邮件地址!');
form.email.focus();
return false;
}
}
form.submit();
}
</script>
<form action="re.php" method="post" name="reg_form">
<p>username: <input type="text" name="username" width=120/>
<p>password: <input type="password" name="password" width=120/>
<p>repassword:<input type="password" name="repassword" width=120/>
<p>email: <input type="text" name="email" width=120/>
<p><input name="" type="button" value="submit" onclick="formSubmit(reg_form);"/>
</form>
你是不是指这个啊