forked from HPQC-LABS/HPQC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.php
29 lines (23 loc) · 853 Bytes
/
database.php
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
<?php
$conn = mysqli_connect('localhost', 'root', '', 'database');
if(mysqli_connect_error()){
echo "<script> alert('Connection error'); </script>";
exit();
}
?>
<?php
if($_SERVER["REQUEST_METHOD"] == "POST"){
if(isset($_POST['submitUnsub'])){ //When the unsub button is clicked
$email = $_POST['email']; //Getting user email
$name = $_POST['name']; //Getting user name
if(filter_var($email, FILTER_VALIDATE_EMAIL){ //ensuring valid email
echo "Valid Email";
$sql = "INSERT INTO user (name, email) VALUES ('$name', '$email')";
mysqli_query($conn, $sql);
} else{
echo "Invalid Email";
}
}
echo "<script> alert('You have successfully unsubscribed'); </script>";
exit();
?>