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'] . " £" . $_POST['drinks_owed'][$i] . " for drinks and £" . $_POST['food_owed'][$i] . " for food for a total of £" . $total . "</p>"; } $paymentObj->setId($payment_id); $paymentObj->setTotal($total); $paymentObj->setDate($_POST['date']); $paymentObj->update(); header("Location: dashboard.php"); exit; } else { // Get list of users for form $user_arr = User::getAll(); // Built debt form input $userObj = new User(); $debt_form = "<select name='user_id[]'>\n";