test.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. //得到提交的用户名和密码
  3. $uname = $_POST['uname'];//改成你自己数据库的字段
  4. $upass = $_POST['upass'];//改成你自己数据库的字段
  5. //action是用来判断是注册还查询
  6. $action = $_POST['action'];
  7. //你自己的数据库地址
  8. $conn = mysql_connect("121.42.8.157","root","~cs3x@2022#123~","xcjkdba",13307);
  9. if(!$conn)
  10. {
  11. die("error");
  12. }
  13. //改成你自己的数据库名称
  14. $result = mysql_select_db("xcjkdba",$conn);
  15. if(!$result)
  16. {
  17. mysql_close($conn);
  18. die("error");
  19. }
  20. //判断用户是登录还是注册
  21. if($action == "login")
  22. {
  23. //匹配用户
  24. $sql = "select x, y, z from his_location_tadiao_result order by loc_time desc limit 100";
  25. //运行
  26. $rs=mysql_query($sql);
  27. if(!$rs)
  28. {
  29. mysql_close($conn);
  30. die("error");
  31. }
  32. $recordCount=mysql_num_rows($rs);
  33. if($recordCount>0)
  34. {
  35. echo "success";
  36. }
  37. else
  38. {
  39. echo "error";
  40. }
  41. }
  42. else if($action == "regist")
  43. {
  44. //设定字符集
  45. $sql = "set names utf8";
  46. //运行
  47. mysql_query($sql);
  48. //查看用户是否存在
  49. $sql = "select *from t_user where uname='".$uname."'";
  50. //运行
  51. $rs=mysql_query($sql);
  52. if(!$rs)
  53. {
  54. mysql_close($conn);
  55. die("error");
  56. }
  57. //获得数据库行数
  58. $recordCount = mysql_num_rows($rs);
  59. if($recordCount>0)
  60. {
  61. mysql_close($conn);
  62. die("exist");
  63. }else
  64. {
  65. //如果不存在就写入数据库
  66. $sql = "insert into t_user(uname,upass) values('".$uname."','".$upass."')";
  67. //运行
  68. $rs=mysql_query($sql);
  69. if(!$rs)
  70. {
  71. mysql_close($conn);
  72. die("error");
  73. }
  74. else
  75. {
  76. echo "success";
  77. }
  78. }
  79. //如果存在就提示
  80. }
  81. else
  82. {
  83. echo "error!";
  84. }
  85. //关闭数据库
  86. mysql_close($conn);
  87. ?>