-
Notifications
You must be signed in to change notification settings - Fork 0
/
registerExpense.php
executable file
·42 lines (32 loc) · 1.07 KB
/
registerExpense.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
require_once './vendor/autoload.php';
session_start();
$owner = $_SESSION['userId'];
$title = $_POST['title'];
$date = $_POST['date'];
$type = $_POST['type'];
$value = $_POST['value'];
$description = $_POST['description'];
use database\Connection;
try{
$connection = Connection::createConnection();
$query = '
INSERT INTO expenses (title, date, type, value, description, owner_id)
VALUES (:title, :date, :type, :value, :description, :owner_id)
';
$statement = $connection->prepare($query);
$statement->bindParam(':title', $title);
$statement->bindParam(':date', $date);
$statement->bindParam(':type', $type);
$statement->bindParam(':value', $value);
$statement->bindParam(':description', $description);
$statement->bindParam(':owner_id', $owner);
$statement->execute();
header("location: expenses.php");
}
catch(PDOException $error)
{
$errorMessage = $error -> getMessage();
echo $errorMessage;
}
?>