Exemplo n.º 1
0
$total = 0;
// Connect to database
$con = mysql_connect(DB_HOST, DB_USER, DB_PW);
if (!$con) {
    die('Could not connect: ' . mysql_error());
}
mysql_select_db(DB_NAME, $con);
// if the form has been submitted
if (isset($_POST['submit_check'])) {
    $paymentObj = new Payment();
    $paymentObj->setUser_id($user_id);
    $paymentObj->create();
    $payment_id = mysql_insert_id();
    $debtObj = new Debt();
    $debtObj->setOwed_to($user_id);
    $debtObj->setPayment_id($payment_id);
    $total = 0;
    for ($i = 0; $i < count($_POST["user_id"]); $i++) {
        $debtObj->setOwed_by($_POST['user_id'][$i]);
        $debt_total = $_POST['drinks_owed'][$i] + $_POST['food_owed'][$i];
        $total += $debt_total;
        $debtObj->setAmount($debt_total);
        $debtObj->create();
        //echo "<p>" . $_POST['user_id'][$i] . " owes " . $_COOKIE['user_id'] . " &pound;" . $_POST['drinks_owed'][$i] . " for drinks and &pound;" . $_POST['food_owed'][$i] . " for food for a total of &pound;" . $total . "</p>";
    }
    $paymentObj->setId($payment_id);
    $paymentObj->setTotal($total);
    $paymentObj->setDate($_POST['date']);
    $paymentObj->update();
    header("Location: dashboard.php");
    exit;