doApiConfig.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. $userid = $_POST['userid'];
  3. $token = $_POST['token'];
  4. $gdkey = $_POST['gdkey'];
  5. $type = $_POST['type'];
  6. include_once("../../untils/conn.php");
  7. if ($con) {
  8. mysqli_query($con, "set names utf8");
  9. // 根据$type的值确定groups的取值
  10. $groups = ($type == "haokeyun") ? "haokeyun" : "gantanhao";
  11. // 查询数据库中的记录
  12. $result = mysqli_query($con, "SELECT * FROM config_api WHERE groups='$groups'");
  13. $row = mysqli_fetch_assoc($result);
  14. $num_rows = mysqli_num_rows($result);
  15. if ($num_rows > 0) {
  16. // 数据库中已存在记录,执行更新操作
  17. $update_query = "UPDATE config_api SET userid='$userid', token='$token'";
  18. if ($type == "haokeyun") {
  19. $update_query .= ", gdkey='$gdkey'";
  20. }
  21. $update_query .= " WHERE groups='$groups'";
  22. $update_result = mysqli_query($con, $update_query);
  23. if ($update_result) {
  24. echo "<script>alert('更新成功'); history.back();</script>";
  25. } else {
  26. echo "<script>alert('更新失败');history.back();</script>";
  27. }
  28. } else {
  29. // 数据库中不存在记录,执行插入操作
  30. $insert_query = "INSERT INTO config_api (groups, userid, token";
  31. $insert_values = "VALUES ('$groups', '$userid', '$token'";
  32. if ($type == "haokeyun") {
  33. $insert_query .= ", gdkey";
  34. $insert_values .= ", '$gdkey'";
  35. }
  36. $insert_query .= ") " . $insert_values . ")";
  37. $insert_result = mysqli_query($con, $insert_query);
  38. if ($insert_result) {
  39. echo "<script>alert('添加成功'); history.back(); </script>";
  40. } else {
  41. echo "<script>alert('添加失败'); history.back(); </script>";
  42. }
  43. }
  44. } else {
  45. echo "<script>alert('数据库连接失败');</script>";
  46. }
  47. $con->close();
  48. ?>