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>
<!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>
相关文章推荐
- ios开发-数据库网络之mac电脑HTML中如何加入java和php角本(3)
- ios开发-数据库网络之用php对mysql的增删改查(6)
- iOS模块开发—登陆注册
- 【iOS开发-92】在mac上如何搭建apache+php+mysql环境用于ios网络测试?
- ios开发-数据库网络之启动MAC系统自带的apachectl服务器(1)
- ios开发-数据库网络之mysql创建数据库,表,基本SQL语句(5)
- 网站开发-php开发手机论坛(6)-登陆注册(1)
- ios开发-数据库网络之html(2)
- IOS开发 - 网络&数据库功能综述
- ios 开发中 --做登陆注册时编译出现的错误和解决方法
- 网站开发-php开发手机论坛(6)-登陆注册(2)
- android开发 使用HttpClient访问网络,post、get方式。注册、登陆、上传文件。
- ios开发-数据库网络之mysql安装 删除 修改密码(4)
- java开发登陆界面时比较数据库字符窜的问题
- 轻型数据库SQLite结合PHP的开发
- FoxPro在网络环境下开发数据库管理软件的一些经验
- 使用PostgreSQL数据库做PHP开发
- 轻型数据库SQLite结合PHP的开发
- SSH(struts+spring+hibernate)迅速开发--第六章 用户登陆和注册(3)
- Visual C# 2008+SQL Server 2005 数据库与网络开发-- 1.1 Visual Studio 2008概述