What common mistake is often made when trying to save data to a database using PHP?

One common mistake when trying to save data to a database using PHP is not properly sanitizing user input, which can lead to SQL injection attacks. To prevent this, it's important to use prepared statements with parameterized queries to securely insert data into the database.

// Establish a database connection
$pdo = new PDO('mysql:host=localhost;dbname=mydatabase', 'username', 'password');

// Prepare a SQL statement with placeholders
$stmt = $pdo->prepare("INSERT INTO users (username, email) VALUES (:username, :email)");

// Bind parameters to the placeholders
$stmt->bindParam(':username', $username);
$stmt->bindParam(':email', $email);

// Set the values of the parameters
$username = $_POST['username'];
$email = $_POST['email'];

// Execute the statement
$stmt->execute();