Commit 5ea09986 authored by Faris Rizki Ekananda's avatar Faris Rizki Ekananda 💬
Browse files

push buy chocolate

parent a5e2cc7a
Pipeline #28537 canceled with stages
......@@ -21,24 +21,32 @@ if ($session['is_superuser']) {
if($_SERVER["REQUEST_METHOD"] === "POST"){
date_default_timezone_set('Asia/Jakarta');
$chocolate_id = $_POST['id'];
$db = $connect_db();
$sql = "SELECT * FROM chocolates WHERE id=$chocolate_id";
$chocolate = $db->query($sql)->fetch();
$address = $_POST['address'];
$chocolate_id = $_POST['id'];
$username = $session['username'];
$amount = $_POST['amount'];
$totalprice = $_POST['totalprice'];
$amount = $_POST['quantity'];
$totalprice = $amount * $chocolate['price'];
$time = date("Y-m-d H:i:s");
try{
// $sql = "";
// $sql = "UPDATE chocolates SET amount = FROM ";
// $sql = "INSERT INTO transactions VALUE";
// $pdo = $connect_db();
// $stmt = $pdo->prepare($sql);
// $stmt->execute();
} catch (Exception $err){
$sql = "INSERT transactions VALUES (:username, :chocolate_id, :amount, :totalprice, :address, :time)";
$stmt = $pdo->prepare($sql);
}
$stmt->bindParams(':username', $username);
$stmt->bindParams(':chocolate_id', $chocolate_id);
$stmt->bindParams(':amount', $amount);
$stmt->bindParams(':totalprice', $totalprice);
$stmt->bindParams(':address', $address);
$stmt->bindParams(':time', $time);
$stmt->execute();
header("location: transaction_history.php");
exit;
}
include('utils/utility.php');
......@@ -107,7 +115,7 @@ if (isset($_GET['id'])) {
<div class="text-title">Amount to buy:</div>
<div class="mod text-subtitle">
<button type="button" id="minus"> - </button>
<input class="mod-number text-subtitle" type="number" id="amountchanged" name="amoungchanged" min="1" max="' . $amount . '">
<input class="mod-number text-subtitle" type="number" id="quantity" name="quantity" min="1" max="' . $amount . '">
<button type="button" id="plus"> + </button>
</div>
</div>
......@@ -135,11 +143,11 @@ if (isset($_GET['id'])) {
// console.log(total);
// console.log(quantity);
document.getElementById('plus').addEventListener('click', function() {
document.getElementById('amountchanged').stepUp();
document.getElementById('quantity').stepUp();
// document.getElementById('total-price').innerHTML = total + quantity * price;
})
document.getElementById('minus').addEventListener('click', function() {
document.getElementById('amountchanged').stepDown();
document.getElementById('quantity').stepDown();
// document.getElementById('total-price').innerHTML = total - quantity * price;
})
</script>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment