-
Notifications
You must be signed in to change notification settings - Fork 0
/
addtocart.php
44 lines (32 loc) · 971 Bytes
/
addtocart.php
1
2
3
4
5
6
7
8
9
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
include_once 'includes/db_config.php';
session_start();
if(!isset($_SESSION['name']))
{
echo "<script type='text/javascript'>
window.location.href='login.php'</script>";
die();
}
$value = $_GET['value'];
$productId = $_GET['productId'];
$price = $_GET['price'];
$userId = $_SESSION['id'];
$db = new Database();
$conn = $db->getConnection();
$query = "SELECT category_id FROM category where category_name = '$value'";
$q = $conn->query($query);
if($q->setFetchMode(PDO::FETCH_ASSOC))
{
while ($r = $q->fetch()){
$categoryId = $r['category_id'];
}
}
$purchaseId = rand(10,100);
$query = "INSERT INTO orderd_item values('', '$userId','$purchaseId', '$categoryId', '$productId', '1', '$price')";
$q = $conn->query($query);
echo '<script language="javascript">';
echo 'alert("The item is added to the cart")';
echo '</script>';
echo "<script type='text/javascript'>
window.location.href='cart.php'</script>";
?>