-
Notifications
You must be signed in to change notification settings - Fork 0
/
hiring.php
45 lines (32 loc) · 1.22 KB
/
hiring.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
45
<?php
include 'includes/session.php';
if(isset($_GET['pay'])){
$payid = $_GET['pay'];
$date = date('Y-m-d');
$conn = $pdo->open();
try{
$stmt = $conn->prepare("INSERT INTO sales (user_id, pay_id, sales_date) VALUES (:user_id, :pay_id, :sales_date)");
$stmt->execute(['user_id'=>$user['id'], 'pay_id'=>$payid, 'sales_date'=>$date]);
$salesid = $conn->lastInsertId();
try{
$stmt = $conn->prepare("SELECT * FROM cart LEFT JOIN products ON products.id=cart.product_id WHERE user_id=:user_id");
$stmt->execute(['user_id'=>$user['id']]);
foreach($stmt as $row){
$stmt = $conn->prepare("INSERT INTO details (sales_id, product_id, quantity) VALUES (:sales_id, :product_id, :quantity)");
$stmt->execute(['sales_id'=>$salesid, 'product_id'=>$row['product_id'], 'quantity'=>$row['quantity']]);
}
$stmt = $conn->prepare("DELETE FROM cart WHERE user_id=:user_id");
$stmt->execute(['user_id'=>$user['id']]);
$_SESSION['success'] = 'Transaction successful. Thank you.';
}
catch(PDOException $e){
$_SESSION['error'] = $e->getMessage();
}
}
catch(PDOException $e){
$_SESSION['error'] = $e->getMessage();
}
$pdo->close();
}
header('location: profile.php');
?>