-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsubs.php
More file actions
41 lines (35 loc) · 1.16 KB
/
subs.php
File metadata and controls
41 lines (35 loc) · 1.16 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
<?php
error_reporting(1);
// Database connection parameters
$servername = "srv1349.hstgr.io";
$username = "u698293704_trainer";
$password = "rk!4yEG/7";
$database = "u698293704_train_subs";
// Create connection
$conn = new mysqli($servername, $username, $password, $database);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Check if email is set and not empty
if(isset($_POST['email']) && !empty($_POST['email'])) {
// Sanitize email input
$email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
// Check if the email is valid
if(filter_var($email, FILTER_VALIDATE_EMAIL)) {
// Prepare SQL statement to insert email into database
$sql = "INSERT INTO subscribers (email) VALUES ('$email')";
if ($conn->query($sql) === TRUE) {
$success_message = "Thank you for subscribing!";
} else {
$error_message = "Error: " . $sql . "<br>" . $conn->error;
}
} else {
$error_message = "Invalid email address!";
}
} else {
$error_message = "Email address is required!";
}
// Close database connection
$conn->close();
?>