So part of my system is I have to submit expense reports, but I can't submit them line by line. The user needs an option to add a new expense so as to be submitted under the same trip. I have part of it working, where a user can add a new expense and this duplicates the original form. However, I'm not sure how I'd go about sending more than 1 form to my database and have it saved as one. Also not sure if the duplicate form will mess with my original based on how it's generated
Original form:
Then here is my PHP to insert the values of the form inputs into the database:
if(isset($_POST['submit'])) {
try {
$sql = "INSERT INTO expenses (userid, submitted_date, receiptid, description, categoryid, clientid, billable, paymentid, currencyid) VALUES (:userid, :submitted_date, :receiptid, :description, :categoryid, :clientid, :billable, :paymentid, :currencyid)";
$statement = $connection->prepare($sql);
$userID = filter_input(INPUT_POST, 'userid');
$statement->bindValue(':userid', $userID, PDO::PARAM_STR);
$subDate = filter_input(INPUT_POST, 'submitted_date');
$statement->bindValue(':submitted_date', $subDate, PDO::PARAM_STR);
$receipt = filter_input(INPUT_POST, 'receiptid');
$statement->bindValue(':receiptid', $receipt, PDO::PARAM_STR);
$description = filter_input(INPUT_POST, 'description');
$statement->bindValue(':description', $description, PDO::PARAM_STR);
$category = filter_input(INPUT_POST, 'categoryid');
$statement->bindValue(':categoryid', $category, PDO::PARAM_STR);
$client = filter_input(INPUT_POST, 'clientid');
$statement->bindValue(':clientid', $client, PDO::PARAM_STR);
$billable = filter_input(INPUT_POST, 'billable');
$statement->bindValue(':billable', $billable, PDO::PARAM_STR);
$paymenttype = filter_input(INPUT_POST, 'paymentid');
$statement->bindValue(':paymentid', $paymenttype, PDO::PARAM_STR);
$currencyid = filter_input(INPUT_POST, 'currencyid');
$statement->bindValue(':currencyid', $currencyid, PDO::PARAM_STR);
print_r($sql);
$statement->execute();
$connection = null;
echo '<script language="javascript">';
echo 'alert("Expense has been added to the database.");';
echo 'window.location.href = "submit.php";';
echo '</script>';
} catch (PDOException $e) {
// for dev
print "We had an error: " . $e->getMessage() . "<br>";
die();
}
?>
<?php } else { ?>
<!DOCTYPE html>
Thanks in advance!