<head> <meta charset="UTF-8"> <title>Checkout Page</title> <link rel="shortcut icon" href="../../images/site_images/icon.png" type="image/png"> <link type="text/css" rel="stylesheet" href="../../css/buy.css" /> </head> <body> <?php if (isset($_SESSION['logged'])) { $stock = checkStockFromDatabase($prod_id, $dbc); if ($stock > 0) { if (checkFunds($_SESSION['user_id'], $dbc, $price)) { buyItem($prod_id, $dbc); echo ' You successfully bought the product <br />' . '<br /> <a href="../main.php">Go to home page</a> '; updateFunds($_SESSION['user_id'], $dbc, $price); $funds_left = showFunds($dbc, $_SESSION['user_id']); echo '<br />Remaining money in your account:' . $funds_left; } else { echo 'No available funds' . '<br /> <a href="../main.php">Go to home page</a> '; } } else { echo ' This product is no more available for purchase or you have no funds. <br /> ' . '<br /> <a href="../main.php">Go to home page</a> '; } } else { if ($_SERVER['REQUEST_METHOD'] == 'POST') { $name = $_POST['name']; $address = $_POST['address']; $city = $_POST['city']; $postal = $_POST['postal_code']; $method = $_POST['method']; $stock = checkStockFromDatabase($prod_id, $dbc);
<?php include_once "../connect.php"; $id1 = $_POST['id']; $amount = $_POST['amount']; echo 'Amount:' . $amount . '<br />'; $query1 = "SELECT * FROM funds where id='{$id1}'"; $result1 = mysqli_query($dbc, $query1) or die(mysqli_error($dbc)); if ($result1) { $balanc = showFunds($dbc, $id1); $query = "UPDATE funds set balance = ({$amount}+{$balanc}) where id = '{$id1}' "; $result = mysqli_query($dbc, $query) or die(mysqli_error($dbc)); echo 'done<br />'; $balance = showFunds($dbc, $id1); echo 'New Balance:' . $balance . '<br /> <br />' . '<a href="../main.php">Go Home</a>'; } else { $query = "INSERT INTO funds values({$id1},{$amount})"; $result = mysqli_query($dbc, $query) or die(mysqli_error($dbc)); echo 'first time'; } function showFunds($link, $user) { $query = "SELECT balance from funds where id={$user}"; $result = mysqli_query($link, $query) or die(mysqli_error($link)); $row = mysqli_fetch_array($result); return $row['balance']; } header("location:wallet.php?id={$id1}&");