1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php
- //得到提交的用户名和密码
- $uname = $_POST['uname'];//改成你自己数据库的字段
- $upass = $_POST['upass'];//改成你自己数据库的字段
- //action是用来判断是注册还查询
- $action = $_POST['action'];
-
- //你自己的数据库地址
- $conn = mysql_connect("121.42.8.157","root","~cs3x@2022#123~","xcjkdba",13307);
- if(!$conn)
- {
- die("error");
- }
-
- //改成你自己的数据库名称
- $result = mysql_select_db("xcjkdba",$conn);
- if(!$result)
- {
- mysql_close($conn);
- die("error");
- }
-
- //判断用户是登录还是注册
- if($action == "login")
- {
- //匹配用户
- $sql = "select x, y, z from his_location_tadiao_result order by loc_time desc limit 100";
-
- //运行
- $rs=mysql_query($sql);
- if(!$rs)
- {
- mysql_close($conn);
- die("error");
- }
- $recordCount=mysql_num_rows($rs);
- if($recordCount>0)
- {
- echo "success";
- }
- else
- {
- echo "error";
- }
- }
- else if($action == "regist")
- {
- //设定字符集
- $sql = "set names utf8";
- //运行
- mysql_query($sql);
-
- //查看用户是否存在
- $sql = "select *from t_user where uname='".$uname."'";
- //运行
- $rs=mysql_query($sql);
- if(!$rs)
- {
- mysql_close($conn);
- die("error");
- }
- //获得数据库行数
- $recordCount = mysql_num_rows($rs);
- if($recordCount>0)
- {
- mysql_close($conn);
- die("exist");
- }else
- {
- //如果不存在就写入数据库
- $sql = "insert into t_user(uname,upass) values('".$uname."','".$upass."')";
- //运行
- $rs=mysql_query($sql);
- if(!$rs)
- {
- mysql_close($conn);
- die("error");
- }
- else
- {
- echo "success";
- }
-
- }
- //如果存在就提示
-
- }
- else
- {
- echo "error!";
- }
-
- //关闭数据库
- mysql_close($conn);
- ?>
|