我有两个 php 文件,一个是 register.php,其中我有 html 表单,我使用 jquery 来验证它。在 process.php 上,如果用户名不退出,我有 php 代码将数据插入数据库的注册表中。
我想通过在 register.php 中隐藏 html 表单来显示段落标记或 div 标记中的通知。这些警报是 1. 用户名已经存在 2. 用户注册成功 3. 注册不成功。
请看一下 process.php 这部分
if($show>0)
{
die("user exits");
}
if($query)
die("registration successfull");
else
die("registration not successful");
我想通过隐藏表单并显示通知来在 register.php 文件上显示这些警报...
简而言之,这里是 register.php 代码..
<script src='jquery-1.9.1.min.js' type="text/javascript"></script>
<script type="text/javascript" src="jquery.validate.js"></script>
<script >
$(document).ready(function(){
$("#formjs").validate({
rules:{
fname:{
required:true,
minlength:5,
maxlength:23
},
lastname:{
required:true,
minlength:5,
maxlength:23
},
and so onoooooooooooo
some part of form
</div>
<form id="formjs" name="formjs" method="post" action="process.php" >
<p>
<label for="name">Name *</label>
<input type="text" name="fname" id="fname" value="" />
</p>
<p>
<label for="lastnamme">LastName *</label>
<input type="text" name="lastname" id="lastname" />
</p>
<p>
<label for="username">Email Address *</label>
<input type="text" name="username" id="username" />
</p>
<p>
这是 process.php 的完整代码...
<?php
if(isset($_POST['username']))
{
$ftname=$_POST['fname'];
$lastname=$_POST['lastname'];
$gender=$_POST['gender'];
$bday=$_POST['day'];
$byear=$_POST['year'];
$bmonth=$_POST['month'];
$username=$_POST['username'];
$password=$_POST['password1'];
$contact=$_POST['contact'];
include('config.php');
$Query = mysql_query("SELECT userid from Account where userid = '$username'") or die(mysql_error());
$show=mysql_num_rows($Query);
if($show>0)
{
die("user name already exits");
}
else
{
$query=mysql_query(" insert into Account (firstname,lastname,gender,bday,byear,bmonth,userid,password,contactno) values
('$ftname','$lastname','$gender','$bday','$byear','$bmonth','$username','$password','$contact')") or die(mysql_error());
if($query)
die("registration sucessfull");
else
die("registration not sucessfull");
//echo "<center>Thank you! You are now a member!</center>";
}
}
?>