您的位置:首页 > 其它

一个简单的注册登录模块

2011-06-13 15:27 549 查看
创建数据库:

create database db;

use db;

create table users (SERIAL int(11) not null primary key auto_increment,ID varchar(20) not null,passwd varchar(20) not null)

会员注册页面 add.php:

<html>
<head>
<meta http-equiv="content-type" content="text/html;charest=GB2312"/>
<title>会员注册</title>
</head>
<body>
<h1 align="center">会员注册</h1>
<form name="form1" action="add_chk.php" method="post">
<p align="center">请输入你要使用的帐号:<input type="text" name="ID"/></p>
<p align="center">请输入你要使用的密码:<input type="password" name="passwd"/></p>
<p align="center">请重新输入密码以确认:<input type="password" name="repasswd"/></p>
<p align="center"><input type="submit" name="提交"/><input type="reset" name="重置"/></p>
</form>
</body>
</html>

注册信息校验页面 add_chk.php:

<?php
$id=$_POST['ID'];
$passwd=$_POST['passwd'];
$repasswd=$_POST['repasswd'];
if($id==null || $passwd==null || $repasswd==NULL)
{ echo "帐号或密码为空,返回重新输入";
}
if ($_POST['passwd']!=$_POST['repasswd'])
{
echo"两次密码不符";
}
$link=mysql_connect("localhost","root","123456");
mysql_select_db("db",$link);
$sqlstr="insert into `users`(SERIAL,ID,passwd) values('','".$_POST['ID']."','".$_POST['passwd']."')";
$result=mysql_query($sqlstr,$link);
echo "注册成功";
mysql_close($link);
?>

登录页面login.php:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312">
<title>会员登录</title>
</head>
<body link="blue" vlink="purple" alink="red">
<h1>会员登录</h1>
<form name="form2" action="chk.php" method="post">
<p align="center">帐号:<input type="text" name="ID"/></p>
<p align="center">密码:<input type="password" name="passwd"/></p>
<p align="center"><input type="submit" name="提交" value="提交"/><input type="reset" name="重置"/>
<h3 align="center"><a href="add.php">注册</a></h3>
</form>
</body>
</html>

登录验证chk.php:

<?php
$link=mysql_connect("localhost","root","123456");
mysql_select_db("db",$link);
$sqlstr="select*from users where ID='".$_POST['ID']."'and passwd='".$_POST['passwd']."'";
$result=mysql_query($sqlstr,$link);
if (mysql_num_rows($result)==1){
echo "<center>会员登录成功</center>";
} else {
echo "<center>会员登录失败</center>";
}
mysql_free_result($result);
mysql_close($link);
?>

程序参考:http://blog.csdn.net/topfzy/archive/2007/06/03/1636146.aspx
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: