-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathinsertdata.php
More file actions
38 lines (30 loc) · 851 Bytes
/
insertdata.php
File metadata and controls
38 lines (30 loc) · 851 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
37
38
<?php
// Database connection parameters
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "things";
// Create connection
$link = mysqli_connect($servername, $username, $password, $dbname);
// Check if connection is established
if (mysqli_connect_error()) {
die("Connection failed: " . mysqli_connect_error());
}
// Fetch data from POST request
$id = $_POST['id'];
$name = $_POST['name'];
$domain = $_POST['domain'];
$propulsion = $_POST['propulsion'];
$sql = "INSERT INTO animals (name, domain, propulsion) VALUES (?, ?, ?)";
$stmt = $link->prepare($sql);
// s for string
$stmt->bind_param("sss", $name, $domain, $propulsion);
$result = $stmt->execute();
if ($result) {
echo "New record created successfully";
} else {
echo "Error: " . $stmt->error;
}
// Close the database connection
$link->close();
?>