-
Notifications
You must be signed in to change notification settings - Fork 15
/
networth.php
80 lines (53 loc) · 2.29 KB
/
networth.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
session_start();
// variable declaration
$errors = [];
// connect to database
$db = mysqli_connect('localhost', 'root', '12345678','registration');
if (isset($_POST['get_networth']) ) {
/**
* Get data from the various fields
* @param $asset
* @param $liability
*/
if( !array_filter($_POST['asset']) ||! array_filter($_POST['liability']) ) {
array_push($errors, "All Fields are required to compute your Networth");
$_SESSION['error'] = $errors;
header('location: dashboard.php');
}else{
// var_dump(isset($_POST['asset'])); die();
// if(!empty($_POST['asset']) && !empty($_POST['liability']) ){
$asset = $_POST['asset'];
$liability = $_POST['liability'];
$sumAsset = array_sum($asset);
$sumLiability = array_sum($liability);
$networthTotal = $sumAsset - $sumLiability;
$_SESSION['net_worth'] = $networthTotal;
$username = $_SESSION['username'];
$id = [];
$findUser = "SELECT id FROM users WHERE username = '$username'";
$results = mysqli_query($db, $findUser);
if ($results->num_rows > 0) {
while($row = $results->fetch_assoc()) {
$id[] = $row['id'];
}
}
$user_id = (int)$id[0];
// $current_timestamp = time();
// $date=date($_POST['current_date']);
//
// var_dump($_POST['current_date']); die();
// $dateSave = date("Y-m-d H:i:s",strtotime($_POST['current_date']));
$dateSave = date("Y-m-d");
// $dateSave = $_POST['current_date'];
// var_dump($dateSave); die();
$query = "INSERT INTO networth (user_id,username, networth,created_at) VALUES ('$user_id', '$username','$networthTotal','$dateSave')";
// $query = "UPDATE networth SET networth = '$networthTotal' WHERE user_id = '$user_id'";
mysqli_query($db, $query);
// var_dump($date_from_timestamp); die();
// if($insertStatement){
header('location: dashboard.php'); //redirect to dasboard.php
// }
// var_dump($_SESSION['net_worth']); die();
}
}