-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsert.php
More file actions
64 lines (52 loc) · 1.87 KB
/
Copy pathinsert.php
File metadata and controls
64 lines (52 loc) · 1.87 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
// Establish database connection
$conn = mysqli_connect("localhost", "root", "", "demo");
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
// Retrieve form data and sanitize inputs
$username = mysqli_real_escape_string($conn, $_POST['username']);
$bazar_details = mysqli_real_escape_string($conn, $_POST['bazar_details']);
$bazarcost = mysqli_real_escape_string($conn, $_POST['bazarcost']);
// Validate form data
if (empty($username) || empty($bazar_details) || empty($bazarcost)) {
echo "Please fill out all fields.";
} else {
// Insert form data into meals table
$query = "INSERT INTO meals (username, bazar_details, bazarcost) VALUES ('$username', '$bazar_details', '$bazarcost')";
if (mysqli_query($conn, $query)) {
echo "Record added successfully.";
} else {
echo "Error: " . $query . "<br>" . mysqli_error($conn);
}
}
// Close database connection
mysqli_close($conn);
?>
<?php
// Establish database connection
$conn = mysqli_connect("localhost", "root", "", "demo");
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
// Retrieve form data and sanitize inputs
$username = mysqli_real_escape_string($conn, $_POST['username']);
$deposit = mysqli_real_escape_string($conn, $_POST['deposit']);
$todays_date = mysqli_real_escape_string($conn, $_POST['todays_date']);
// Validate form data
if (empty($username) || empty($deposit) || empty($date)) {
echo "Please fill out all fields.";
} else {
// Insert form data into users table
$query = "INSERT INTO users (username, deposit, todays_date) VALUES ('$username', '$deposit', '$date')";
if (mysqli_query($conn, $query)) {
echo "Record added successfully.";
} else {
echo "Error: " . $query . "<br>" . mysqli_error($conn);
}
}
// Close database connection
mysqli_close($conn);
?>