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

登陆页面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>



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值