-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsert.php
More file actions
43 lines (36 loc) · 1.2 KB
/
insert.php
File metadata and controls
43 lines (36 loc) · 1.2 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
<?php
// Database connection
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "mydatabase";
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die(json_encode(['success' => false, 'error' => 'Database connection failed']));
}
// Get JSON input
$data = json_decode(file_get_contents('php://input'), true);
if (isset($data['email'], $data['thumbnail'], $data['title'], $data['newsLink'], $data['websiteLogo'], $data['websiteName'])) {
// Prepare and bind statement to avoid SQL injection
$stmt = $conn->prepare("INSERT INTO saved (email, thumbnail, title, newsLink, websiteLogo, websiteName) VALUES (?, ?, ?, ?, ?, ?)");
$stmt->bind_param(
"ssssss",
$data['email'],
$data['thumbnail'],
$data['title'],
$data['newsLink'],
$data['websiteLogo'],
$data['websiteName']
);
if ($stmt->execute()) {
echo json_encode(['success' => true]);
} else {
echo json_encode(['success' => false, 'error' => $stmt->error]);
}
$stmt->close();
} else {
echo json_encode(['success' => false, 'error' => 'Invalid input']);
}
$conn->close();
?>