Сохранение товара - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.

Name: Сохранение товара fullscreencopydownloadembedprint


Your result can be seen below.

Result of php executing





Full code of Сохранение товара.php

  1. <?php
  2. if($_GET['page']=='products' && isset($_GET['do']) && ($_GET['action']=='subadd' || $_GET['action']=='subedit' || $_GET['action']=='subdelete')) { //РЕДАКТИРОВАНИЕ ПОДТОВАРОВ
  3.  
  4. $id = intval($_POST['id']) >0 ? intval($_POST['id']) : intval($_GET['id']);
  5. $subid = intval($_POST['subid']) >0 ? intval($_POST['subid']) : intval($_GET['subid']);
  6. $cfilters = $_POST['cfilters'];
  7. $price = intval($_POST['price']);
  8. $count = intval($_POST['count']);
  9.  
  10. $redis = new Redis();
  11. $redis->connect('127.0.0.1', 6379);
  12.  
  13. if($_GET['action']=='subedit' || $_GET['action']=='subdelete') {
  14.        
  15.         $id = $dbh->query("SELECT `productid` FROM `subproducts` WHERE `id`=$subid")->fetchColumn();
  16.  
  17.                 $filter_values = $dbh->query("SELECT `productid`, `valueid` FROM `subproduct_filter_values` WHERE `subproductid`=".$subid)->fetchAll(PDO::FETCH_ASSOC);
  18.             foreach ($filter_values as $filter_value){
  19. $redis->setBit($filter_value['valueid'], intval($filter_value['productid']), 0);
  20.                 }
  21.  
  22. $res3 = $dbh->prepare("DELETE FROM `subproducts` WHERE `id`=:subproductid");
  23. $res3->execute(["subproductid" => $subid]);
  24.  
  25. $res3 = $dbh->prepare("DELETE FROM `subproduct_filter_values` WHERE `subproductid`=:subproductid");
  26. $res3->execute(["subproductid" => $subid]);
  27.                
  28.        
  29. }
  30.  
  31.  
  32. if($_GET['action']=='subadd') {
  33.         $res4 = $dbh->prepare("INSERT INTO `subproducts` (`productid`, `price`, `count`) VALUES (:productid, :count, :count)");
  34.         $res4->bindParam(':productid', $id, PDO::PARAM_INT);
  35.         $res4->bindParam(':price', $price, PDO::PARAM_INT);
  36.         $res4->bindParam(':count', $count, PDO::PARAM_INT);
  37.         $res4->execute();
  38.        
  39.         $subid = $dbh->query("SELECT `id` FROM `subproducts` WHERE `productid`=$id ORDER BY `id` DESC LIMIT 1")->fetchColumn();
  40. }
  41.  
  42.  
  43. if($_GET['action']=='subadd' || $_GET['action']=='subedit') {
  44.        
  45.         $sfilters = explode("|", $cfilters);
  46.        
  47.         foreach ($sfilters as $filters) {
  48.                 $filter = explode("_", $filters);
  49.                
  50.        
  51.         $res4 = $dbh->prepare("INSERT INTO `subproduct_filter_values`(`productid`, `subproductid`, `filterid`, `valueid`) VALUES (:productid, :subproductid, :filterid, :valueid)");
  52.         $res4->bindParam(':productid', $id, PDO::PARAM_INT);
  53.         $res4->bindParam(':subproductid', $subid, PDO::PARAM_INT);
  54.         $res4->bindParam(':filterid', $filter[0], PDO::PARAM_INT);
  55.         $res4->bindParam(':valueid', $filter[1], PDO::PARAM_INT);
  56.         $res4->execute();
  57.        
  58.         $redis->setBit($filter[1], $id, 1);  
  59.                
  60.         }
  61.        
  62. }
  63.  
  64. if($_GET['action']=='subadd')header('Location: index.php?page=products&action=subedit&subid='.$subid);
  65. if($_GET['action']=='subedit')header('Location: index.php?page=products&action=subedit&subid='.$subid);
  66. if($_GET['action']=='subdelete')header('Location: index.php?page=products');
  67.         die();
  68.  
  69. }
  70. ?>
File Description
  • Сохранение товара
  • PHP Code
  • 20 Dec-2020
  • 2.61 Kb
You can Share it: