php add to cart telegram sessions

Solutions on MaxInterview for php add to cart telegram sessions by the best coders in the world

showing results for - "php add to cart telegram sessions"
Callan
14 Feb 2017
1$link = mysqli_connect(...) or die("Error " . mysqli_error($link));
2$query = "SELECT * FROM MMT_BOT WHERE CHAT_ID = '".$_POST["chat"]."'" or die("Error in the consult.." . mysqli_error($link));
3$result = mysqli_query($link, $query);
4$res_num = mysqli_num_rows($result);
5if ($res_num === 0) {
6        $query = "INSERT INTO MMT_BOT (CHAT_ID, SESSION) VALUES ('".$_POST["chat"]."','".$_POST["session"]."')" or die("Error in the consult.." . mysqli_error($link));
7        $link->query($query);
8        $query = "SELECT * FROM MMT_BOT WHERE CHAT_ID = '".$_POST["chat"]."'" or die("Error in the consult.." . mysqli_error($link));
9        $result = mysqli_query($link, $query);
10    } else {
11        $query = "UPDATE MMT_BOT SET SESSION = '".$_POST["session"]."' WHERE CHAT_ID = '".$_POST["chat"]."'" or die("Error in the consult.." . mysqli_error($link));
12        $link->query($query);
13        $query = "SELECT * FROM MMT_BOT WHERE CHAT_ID = '".$_POST["chat"]."'" or die("Error in the consult.." . mysqli_error($link));
14        $result = mysqli_query($link, $query);
15    }
16        $rows = array();
17            while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
18              $rows[] = array('sessione' => $row['SESSION'],'chat_id' => $row['CHAT_ID']);
19        }
20echo json_encode($rows);
David
28 Mar 2018
1<?php session_start();
2#cart.php - A simple shopping cart with add to cart, and remove links
3 //---------------------------
4 //initialize sessions
5
6//Define the products and cost
7$products = array("product A", "product B", "product C");
8$amounts = array("19.99", "10.99", "2.99");
9
10//Load up session
11 if ( !isset($_SESSION["total"]) ) {
12   $_SESSION["total"] = 0;
13   for ($i=0; $i< count($products); $i++) {
14    $_SESSION["qty"][$i] = 0;
15   $_SESSION["amounts"][$i] = 0;
16  }
17 }
18
19 //---------------------------
20 //Reset
21 if ( isset($_GET['reset']) )
22 {
23 if ($_GET["reset"] == 'true')
24   {
25   unset($_SESSION["qty"]); //The quantity for each product
26   unset($_SESSION["amounts"]); //The amount from each product
27   unset($_SESSION["total"]); //The total cost
28   unset($_SESSION["cart"]); //Which item has been chosen
29   }
30 }
31
32 //---------------------------
33 //Add
34 if ( isset($_GET["add"]) )
35   {
36   $i = $_GET["add"];
37   $qty = $_SESSION["qty"][$i] + 1;
38   $_SESSION["amounts"][$i] = $amounts[$i] * $qty;
39   $_SESSION["cart"][$i] = $i;
40   $_SESSION["qty"][$i] = $qty;
41 }
42
43  //---------------------------
44  //Delete
45  if ( isset($_GET["delete"]) )
46   {
47   $i = $_GET["delete"];
48   $qty = $_SESSION["qty"][$i];
49   $qty--;
50   $_SESSION["qty"][$i] = $qty;
51   //remove item if quantity is zero
52   if ($qty == 0) {
53    $_SESSION["amounts"][$i] = 0;
54    unset($_SESSION["cart"][$i]);
55  }
56 else
57  {
58   $_SESSION["amounts"][$i] = $amounts[$i] * $qty;
59  }
60 }
61 ?>
62 <h2>List of All Products</h2>
63 <table>
64   <tr>
65   <th>Product</th>
66   <th width="10px"> </th>
67   <th>Amount</th>
68   <th width="10px"> </th>
69   <th>Action</th>
70   </tr>
71 <?php
72 for ($i=0; $i< count($products); $i++) {
73   ?>
74   <tr>
75   <td><?php echo($products[$i]); ?></td>
76   <td width="10px"> </td>
77   <td><?php echo($amounts[$i]); ?></td>
78   <td width="10px"> </td>
79   <td><a href="?add=<?php echo($i); ?>">Add to cart</a></td>
80   </tr>
81   <?php
82 }
83 ?>
84 <tr>
85 <td colspan="5"></td>
86 </tr>
87 <tr>
88 <td colspan="5"><a href="?reset=true">Reset Cart</a></td>
89 </tr>
90 </table>
91 <?php
92 if ( isset($_SESSION["cart"]) ) {
93 ?>
94 <br/><br/><br/>
95 <h2>Cart</h2>
96 <table>
97 <tr>
98 <th>Product</th>
99 <th width="10px"> </th>
100 <th>Qty</th>
101 <th width="10px"> </th>
102 <th>Amount</th>
103 <th width="10px"> </th>
104 <th>Action</th>
105 </tr>
106 <?php
107 $total = 0;
108 foreach ( $_SESSION["cart"] as $i ) {
109 ?>
110 <tr>
111 <td><?php echo( $products[$_SESSION["cart"][$i]] ); ?></td>
112 <td width="10px"> </td>
113 <td><?php echo( $_SESSION["qty"][$i] ); ?></td>
114 <td width="10px"> </td>
115 <td><?php echo( $_SESSION["amounts"][$i] ); ?></td>
116 <td width="10px"> </td>
117 <td><a href="?delete=<?php echo($i); ?>">Delete from cart</a></td>
118 </tr>
119 <?php
120 $total = $total + $_SESSION["amounts"][$i];
121 }
122 $_SESSION["total"] = $total;
123 ?>
124 <tr>
125 <td colspan="7">Total : <?php echo($total); ?></td>
126 </tr>
127 </table>
128 <?php
129 }
130 ?>