您的位置:首页 > 理论基础 > 计算机网络

ios开发-数据库网络之php的登陆和注册(7)

2016-11-09 14:59 381 查看
登陆页面index.html

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<title>注册页面</title>
<meta name="Generator" content="Cocoa HTML Writer">
<meta name="CocoaVersion" content="1504.6">
<style type="text/css">
</style>
</head>
<body>
<center>欢迎</center>
<hr><!--横线-->
<!--get不安全,post安全-->
<form action="login.php" method="post">
<table align="center" border="1" width="300">
<tr><td>账号</td><td><input maxlength="10" name="uname"></td></tr>
<tr><td>密码</td><td><input type="password" maxlength="10" name="upass"></td></tr>
<tr><td><input type="submit" value="登陆" name="action"></td><td><input type="submit" value="注册" name="action"></td></tr>
</table>
</form>
</body>
</html>

登陆注册提交页面login.php
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
</head>
<body>
<?
//得到提交的用户名和密码
//$uname=$_GET['uname'];
//$upass=$_GET['upass'];
$uname=$_POST['uname'];
$upass=$_POST['upass'];
$uname=trim($uname);//剔除用户名两端的空格
$upass=trim($upass);//剔除密码两端的空格
if($uname==""||$upass=="")//如果用户名或密码有空的
{
//导航回到index.html
echo "<script>location.href='index.html';</script>";
exit();
}
$action=$_POST['action'];
$conn=mysql_connect("127.0.0.1","root","123456");
if(!conn){
die("连接数据库失败!");
}
$result=mysql_select_db("wondgirl",$conn);
if(!result){
mysql_close($conn);
die("指定数据库失败!");
}
if ($action=="登陆") {
$sql="select * from t_user where uname='".$uname."' and upass='".$upass."'";
//echo $sql;
$rs=mysql_query($sql);
if(!rs)
{
mysql_close($conn);
die("查询数据失败!");
}

$recordCount=mysql_num_rows($rs);
if($recordCount>0)//如果存在就显示提示信息
{
echo "登陆成功!";
}
else
{
echo "对不起,用户登陆失败,请检查用户名和密码重新<a href='index.html'>登陆</a>.";
}
}
else if($action=="注册"){
//查看用户是否存在
$sql="select * from t_user where uname='".$uname."'";
$rs=mysql_query($sql);
if(!rs)
{
mysql_close($conn);
die("查询数据失败!");
}

$recordCount=mysql_num_rows($rs);
if($recordCount>0)//如果存在就显示提示信息
{
mysql_close($conn);
die("对不起,该用户已存在,你必须更换另一个用户名!想返回重新<a href='index.html'>注册</a>吗?");
}
else
{//如果不存在 把当前用户写到数据库中
$sql="insert into t_user(uname,upass) values('".$uname."','".$upass."')";
echo $sql;
$rs=mysql_query($sql);
if(!rs)
{
mysql_close($conn);
die("用户注册失败,请稍后再试!");
}
else
{
echo "恭喜你,注册成功,你可以用它去<a href='index.html'>登陆</a>了!";
}

}

}
else{
echo "error!";
}
?>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息