-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubmit.php
More file actions
46 lines (37 loc) · 1.1 KB
/
Copy pathsubmit.php
File metadata and controls
46 lines (37 loc) · 1.1 KB
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
<?php
$servername = "localhost";
$username = "root";
$password = "Citi@420";
$dbname = "detrack";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// If form is submitted, insert the data into the database
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$edate = $_POST['edate'];
$eitem = $_POST['eitem'];
$eamount = $_POST['eamount'];
$etype = $_POST['etype'];
$sql = "INSERT INTO deentry (edate, eitem, eamount, etype)
VALUES ('$edate', '$eitem', '$eamount', '$etype')";
if ($conn->query($sql) === true) {
echo "Record added successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
// Select all the entries from the database
$sql = "SELECT edate, eitem, eamount, etype FROM deentry";
$result = $conn->query($sql);
// Store the results in an array
$entries = array();
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$entries[] = $row;
}
}
$conn->close();
?>