-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_spending.php
89 lines (76 loc) · 2.79 KB
/
add_spending.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
81
82
83
84
85
86
87
88
89
<?php
session_start();
$connect = mysqli_connect('localhost', 'root', '', 'moneyliteracy');
$students_name = $_SESSION['students_name'];
$q="SELECT * from students WHERE students_id =".$_SESSION['stu_id'];
$res=mysqli_query($connect,$q) or die("Can't Execute Query...");
$row = mysqli_fetch_assoc($res);
?>
<!DOCTYPE html>
<html>
<head>
<title>ADD SPENDING</title>
<style>
h1{
text-align:center;
font-family: arial;
font-weight:bold;
}
form{
background-color: white;
margin:5% 30%;
border-radius:10px;
border:2px solid grey;
padding:10px 20px;
}
a:hover{
color:red;
cursor:pointer;
}
</style>
</head>
<body>
<h1>Add Your Spending for today</h1>
<form name="add_spending" action="add_spending.php" method="post" enctype="multipart/form-data">
<table>
<tr>
<td>Date: </td>
<td><input type="datetime-local" name="date"/></td>
</tr><tr></tr>
<tr>
<td>Amount of spending for today: </td>
<td><input type="text" name="total"/></td>
</tr><tr></tr>
<tr>
<td>Details: </td>
<td><input type="text" name="details"/></td>
</tr><tr></tr>
<tr>
<td colspan="1"><input type="button" name="cancel" value="CANCEL" onClick="window.location='student_spending.php';"/></td>
<td colspan="2"><input type="submit" name="submit" value="ADD"></td>
</tr>
</table>
</form>
<?php
mysqli_connect("localhost", "root", "");
mysqli_select_db($connect, "moneyliteracy");
if(isset($_POST['submit']))
{
$date = $_POST['date'];
$total = $_POST['total'];
$details = $_POST['details'];
$query = "insert into spending (spending_date, spending_total, spending_details, students_id ) VALUES ('$date', '$total', '$details', ".$_SESSION['stu_id'].")";
if(mysqli_query($connect, $query))
{
echo ("<script LANGUAGE='JavaScript'>
window.alert('Spending Succesfully Added!');
window.location.href='student_spending.php';
</script>");
}
else {
echo "<script>alert('Spending Failed to Add!')</script>";
}
}
?>
</body>
</html>