- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
<?php
if(isset($_GET['action']) && $_GET['action']=="add"){
$id=intval($_GET['id']);
if(isset($_SESSION['cart'][$id])){
$_SESSION['cart'][$id]['quantity']++;
}else{
$sql_s="SELECT * FROM products
WHERE id_product={$id}";
$query_s=mysqli_query($sql_s);
if(mysqli_num_rows($query_s)!=0){
$row_s=mysqli_fetch_array($query_s);
$_SESSION['cart'][$row_s['id_product']]=array(
"quantity" => 1,
"price" => $row_s['price'] );
}else{
$message="This product id it's invalid!"; } } } ?>
<h1>Product List</h1>
<?php
if(isset($message)){
echo "<h2>$message</h2>"; }
?>
<table>
<tr>
<th>Name</th>
<th>Description</th>
<th>Price</th>
<th>Action</th>
</tr>
<?php
$mysqli = new mysqli('……','root','……','tutorials');
$sql = 'SELECT name,description,price, id_product FROM products'; // select from mysql
$result = $mysqli->query($sql);
while($row = $result->fetch_array()){
?>
<tr>
<td><?php echo $row['name'] ?></td>
<td><?php echo $row['description'] ?></td>
<td><?php echo $row['price'] ?>$</td>
<td><a href="index.php?page=products&action=add&id=<?php echo $row['id_product'] ?>">Add to cart</a></td>
</tr>
<?php
}
?>
</table>
guest8 13.12.2018 22:50 # −999
guest8 14.12.2018 01:35 # −999
MouseZver 14.12.2018 04:16 # 0
Hot_Chick 14.12.2018 15:07 # 0
MouseZver 16.12.2018 10:40 # 0
homo 14.12.2018 12:35 # 0
Hot_Chick 14.12.2018 15:06 # 0
homo 14.12.2018 16:53 # 0
MouseZver 16.12.2018 10:42 # 0
zhigolo 14.12.2018 16:46 # −1
guest8 16.12.2018 13:01 # −999
guest8 16.12.2018 13:12 # −999
MouseZver 18.12.2018 09:25 # 0