忙了几个小时终于把上周没完成的用户登录写好了,很简易,没加入会话技术,以后再加吧....哈哈,颇为自豪啊!!
login.html (登录界面)
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>用户登录</title>
</head>
<body>
<h1>用户登录</h1>
<form method="post" action="success.php">
用户名:<input type="text" name="username"/><br/>
密码 :<input type="password" name="password"/><br/>
<input type="submit" value="提交"/>
<input type="reset" value="重新填写"/>
</form>
</body>
</html>
success.php(登录成功界面)
<?php
$username=$_POST['username'];
$password=md5($_POST['password']);
if((empty($username))||(empty($password)))
die("请输出用户名和密码!!!");
//连接数据库
@$conn=new mysqli("localhost","root","123456","php");
if(!$conn)
die("数据库连接失败!!");
$query="select count(*) from user where username='$username'and password='$password'";
$result=$conn->query($query);
if(!$result)
die("用户名或密码不正确!!!");
else
echo "用户登录成功!!";
?>
regist.html(注册界面)
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>用户注册</title>
</head>
<body>
<h1>用户注册</h1>
<form method="post" action="regist.php">
用户名:<input type="text" name="username"/><br/>
密码:
<input type="password" name="password"/><br/>
邮箱:
<input type="text" name="email"/><br/>
<input type="submit" value="提交"/>
<input type="reset" value="重置"/>
</form>
</body>
</html>
regist.php(判断注册)
<?php
//接受数据,转义,并对密码加密.
$username= addslashes($_POST['username']);
$password=addslashes($_POST['password']);
$password_c=md5($password);
$email=addslashes($_POST['email']);
//判断数据的有效性
if(empty($username)||empty($password)||empty($email))
die("请正确填写!!");
//想数据库写入数据
@$conn=new mysqli("localhost","root","123456","php");
if(!$conn)
die("数据库连接失败!!");
//else echo "数据库连接成功!";
$query="insert into user (username,password,email) values ('$username','$password_c','$email')";
$result=$conn->query($query);
if(!$result)
die("注册失败!!");
if ($conn->affected_rows)
echo "注册成功!!";
?>
sql(数据库)
create table user(
id int primary key auto_increment,
username varchar(30),
password varchar(50),
email varchar(30)
);
有什么意见和建议,交流,求教(不敢当哈哈)的,可以留言,新浪微博@Blue7Wings都行哈.....