-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubmit.php
More file actions
36 lines (29 loc) · 875 Bytes
/
submit.php
File metadata and controls
36 lines (29 loc) · 875 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
// Connect to the database
$servername = "127.0.0.1";
$username = "root";
$password = "";
$dbname = "my_database";
$port = 3306;
$conn = new mysqli($servername, $username, $password, $dbname, $port);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Insert data into the database
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$name = $_POST['name'];
$age = $_POST['age'];
$email = $_POST['email'];
$sql = "INSERT INTO records (name, age, email) VALUES ('$name', '$age', '$email')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
$conn->close();
// Redirect back to the main page after submission
header("Location: index.html");
exit;
?>