What are the potential pitfalls of storing form data in a MySQL database compared to sending it via email using PHP?

Storing form data in a MySQL database provides a more secure and organized way to manage and retrieve the information compared to sending it via email using PHP. However, potential pitfalls of storing form data in a database include the risk of data breaches if proper security measures are not in place, the need for regular backups to prevent data loss, and the complexity of setting up and maintaining a database compared to simply sending an email.

// Connect to MySQL database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Insert form data into database
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];

$sql = "INSERT INTO form_data (name, email, message) VALUES ('$name', '$email', '$message')";

if ($conn->query($sql) === TRUE) {
    echo "Form data stored successfully in database.";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();