What is the issue with inserting emails into the database in PHP?
When inserting emails into a database in PHP, it is important to properly sanitize the input to prevent SQL injection attacks. This can be done by using prepared statements with parameterized queries to securely insert the email into the database.
// Assuming $email contains the email to be inserted into the database
// Create a database connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Prepare a SQL statement with a parameterized query
$stmt = $conn->prepare("INSERT INTO emails (email) VALUES (?)");
$stmt->bind_param("s", $email);
// Execute the statement
$stmt->execute();
// Close the statement and connection
$stmt->close();
$conn->close();