第一段代码
<html>
<head><title>会员注册系统</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body bgcolor="white" text="black" link="blue" vlink="purple" alink="red">
<h1 align="center">会员注册</h1>
<form method=post action=add_chk.php name="AddForm">
<p align="center">请输入你要使用的帐号:<input type="text" name="id"></p>
<p align="center">请输入你要使用的密码:<input type="password" name="password"></p>
<p align="center">请重复输入你的密码以确认:<input type="password" name="repassword"></p>
<p align="center"><input type="submit" name="submit" value="注册"><input type="reset" name="reset" value="重设"></p>
</form>
</body>
</html>
第二段代码
<?php
include_once("sql_connect.php");
include_once("my_msg.php");
?>
<?php
//检查数据
if($_POST['id']=='' or $_POST['password']==''or $_POST['repassword']=='')
{
my_msg("字段不可空白","add.html");
}
if($_POST['password']!=$_POST['repassword'])
{
my_msg("密码不相同,请输入相同的密码!","add.html");
}
$sqlstr="insert into member values('','".$_POST['id']."','".$_POST['password']."',1,1)";
//组合sql
$result=mysql_query($sqlstr,$link);
//执行sql
//跳至窗口
my_msg("添加用户成功,请记住你的帐号和密码!","login.html");
mysql_free_result($result);
mysql_close($link);
?>
第二段代码里我已经检查用户名和密码以及重复输入的密码都不能为空,而且密码和重复输入的密码必须相同。可是在第一段代码生成的网页中不管输不输用户名和密码以及确认密码或密码和确认密码不同,点确定按钮后都会在数据库表中生成一条记录。
<html>
<head><title>会员注册系统</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body bgcolor="white" text="black" link="blue" vlink="purple" alink="red">
<h1 align="center">会员注册</h1>
<form method=post action=add_chk.php name="AddForm">
<p align="center">请输入你要使用的帐号:<input type="text" name="id"></p>
<p align="center">请输入你要使用的密码:<input type="password" name="password"></p>
<p align="center">请重复输入你的密码以确认:<input type="password" name="repassword"></p>
<p align="center"><input type="submit" name="submit" value="注册"><input type="reset" name="reset" value="重设"></p>
</form>
</body>
</html>
第二段代码
<?php
include_once("sql_connect.php");
include_once("my_msg.php");
?>
<?php
//检查数据
if($_POST['id']=='' or $_POST['password']==''or $_POST['repassword']=='')
{
my_msg("字段不可空白","add.html");
}
if($_POST['password']!=$_POST['repassword'])
{
my_msg("密码不相同,请输入相同的密码!","add.html");
}
$sqlstr="insert into member values('','".$_POST['id']."','".$_POST['password']."',1,1)";
//组合sql
$result=mysql_query($sqlstr,$link);
//执行sql
//跳至窗口
my_msg("添加用户成功,请记住你的帐号和密码!","login.html");
mysql_free_result($result);
mysql_close($link);
?>
第二段代码里我已经检查用户名和密码以及重复输入的密码都不能为空,而且密码和重复输入的密码必须相同。可是在第一段代码生成的网页中不管输不输用户名和密码以及确认密码或密码和确认密码不同,点确定按钮后都会在数据库表中生成一条记录。
{
my_msg("字段不可空白","add.html");
}
if($_POST['password']!=$_POST['repassword'])
{
my_msg("密码不相同,请输入相同的密码!","add.html");
}
无论这些结果如何,下面的代码都会执行啊!!!!!要加上else呀
$sqlstr="insert into member values('','".$_POST['id']."','".$_POST['password']."',1,1)";
//组合sql
$result=mysql_query($sqlstr,$link);
//执行sql
//跳至窗口
my_msg("添加用户成功,请记住你的帐号和密码!","login.html");
mysql_free_result($result);
mysql_close($link);
if(!empty($_POST['password'])&&!empty($_POST['repassword'])){
if($_POST['password']==$_POST['repassword']){
$sqlstr="insert into member values('','".$_POST['id']."','".$_POST['password']."',1,1)";
//组合sql
$result=mysql_query($sqlstr,$link);
//执行sql
//跳至窗口
my_msg("添加用户成功,请记住你的帐号和密码!","login.html");
mysql_free_result($result);
mysql_close($link);
}else{
my_msg("密码不相同,请输入相同的密码!","add.html");
}
}else{
my_msg("字段不可空白","add.html");
}
}