-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdatecart.php
More file actions
49 lines (42 loc) · 1.11 KB
/
updatecart.php
File metadata and controls
49 lines (42 loc) · 1.11 KB
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
46
47
48
<?php
session_start();
$cartid = $_POST["cartid"];
$qty = $_POST["qty"];
// if (isset($_SESSION['id'])) {
// echo $userid = $_SESSION['id'];
// }
// else{
// header("Location:login.php");
//
// }
updateitem();
function updateitem() {
global $qty, $cartid;
// Create database connection.
$config = parse_ini_file('../../private/db-config.ini');
$conn = new mysqli($config['servername'], $config['username'], $config['password'], 'project1004');
// Check connection
if ($conn->connect_error)
{
$errorMsg = "Connection failed: " . $conn->connect_error;
$result = 0;
}
else
{
$stmt = $conn->prepare("UPDATE cart SET qty = ? WHERE id= ? ");
$stmt->bind_param("ii", $qty,$cartid );
$stmt->execute();
if($stmt >= 1)
{
echo '<script>window.location.href = "cart.php";</script>';
}
else
{
echo "Prepare failed: (". $conn->errno.") ".$conn->error."<br>";
}
$stmt->close();
}
$conn->close();
return $result;
}
?>