-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubmit.php
More file actions
34 lines (28 loc) · 865 Bytes
/
submit.php
File metadata and controls
34 lines (28 loc) · 865 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
<?php
// Database connection info
$servername = "localhost";
$username = "root"; // use your MySQL user (probably 'root')
$password = ""; // use your MySQL password
$database = "sample_db";
// Create connection
$conn = new mysqli($servername, $username, $password, $database);
// Check for connection error
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Get form data
$name = $_POST['name'];
$email = $_POST['email'];
$age = $_POST['age'];
// Prepare and bind
$stmt = $conn->prepare("INSERT INTO users (name, email, age) VALUES (?, ?, ?)");
$stmt->bind_param("ssi", $name, $email, $age);
// Execute and check result
if ($stmt->execute()) {
echo "Form submitted and data inserted successfully!";
} else {
echo "Error: " . $stmt->error;
}
$stmt->close();
$conn->close();
?>