uplistchannel.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. include_once("../../untils/conn.php");
  3. // mysqli_query($con, "set names utf8");
  4. // 获取要更新的商品ID和渠道名称
  5. $id = $_POST["id"];
  6. $channel_name = $_POST["channel_name"];
  7. // 查询渠道名称对应的渠道ID
  8. $sql = "SELECT channel_id FROM channel WHERE channel_name = '$channel_name'";
  9. $result = mysqli_query($con, $sql);
  10. $row = mysqli_fetch_assoc($result);
  11. $channel_id = $row["channel_id"];
  12. // 查询商品的已有渠道数
  13. $sql = "SELECT channel, channel_one, channel_two FROM list WHERE id = '$id'";
  14. $result = mysqli_query($con, $sql);
  15. $row = mysqli_fetch_assoc($result);
  16. // 判断要写入的渠道字段
  17. if ($row["channel"] == null) {
  18. $field = "channel";
  19. } elseif ($row["channel_one"] == null) {
  20. $field = "channel_one";
  21. } elseif ($row["channel_two"] == null) {
  22. $field = "channel_two";
  23. } else {
  24. // 商品已有三个渠道,加入失败
  25. // echo "加入失败,每个商品只能添加三个渠道";
  26. echo ("<script>alert('加入失败,每个商品只能添加三个渠道');history.back();</script>");
  27. exit;
  28. }
  29. // 更新商品的渠道字段
  30. $sql = "UPDATE list SET $field = '$channel_id' WHERE id = '$id'";
  31. if(mysqli_query($con, $sql)) {
  32. // 更新成功,弹出加入成功提示
  33. // echo "加入成功";
  34. echo ("<script>alert('加入渠道成功');history.back();</script>");
  35. } else {
  36. // 更新失败,提示加入失败
  37. echo "加入失败,请稍后重试";
  38. echo ("<script>alert('加入渠道失败');history.back();</script>");
  39. }