-
Notifications
You must be signed in to change notification settings - Fork 0
/
maillist.php
executable file
·46 lines (38 loc) · 1.2 KB
/
maillist.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
// Include config file
require_once "dbconfig.php";
// Define variables and initialize with empty values
$emailaddress = "";
$emailaddress_err = "";
// Processing form data when form is submitted
if($_SERVER["REQUEST_METHOD"] == "POST"){
//Validate email address
if(empty(trim($_POST["emailaddress"]))){
$emailaddress_err = "Please enter an email address.";
} elseif(strlen(trim($_POST["emailaddress"])) < 6){
$emailaddress_err = "Incorrect email format. ";
} else{
$emailaddress = trim($_POST["emailaddress"]);
}
// Check input errors before inserting in database
if(empty($emailaddress_err)){
// Prepare an insert statement
$sql = "INSERT INTO emaillist (emailaddress) VALUES (?)";
if($stmt = mysqli_prepare($conn, $sql)){
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "s", $param_emailaddress);
// Set parameters
$param_emailaddress = $emailaddress;
// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt)){
// Redirect to login page
header("Location: a.home.php");
} else{
echo "Something went wrong. Please try again later.";
}
}
}
// Close connection
mysqli_close($conn);
}
?>