-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsert_data.php
More file actions
36 lines (30 loc) · 965 Bytes
/
Copy pathinsert_data.php
File metadata and controls
36 lines (30 loc) · 965 Bytes
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
<?php
// Database credentials
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "demo";
// Create a new mysqli object
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Get the data from the form
$id = $_POST['id'];
$username = $_POST['username'];
$totalmeals = $_POST['totalmeals'];
$deposit = $_POST['deposit'];
$userstotalmeals = $_POST['userstotalmeals'];
$dailymeals = $_POST['dailymeals'];
// Prepare the SQL query
$sql = "INSERT INTO meals (id, username, totalmeals, deposit, userstotalmeals, dailymeals, date) VALUES ('$id', '$username', '$totalmeals', '$deposit', '$userstotalmeals', '$dailymeals', NOW())";
// Execute the query
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
// Close the connection
$conn->close();
?>