What are the potential pitfalls when reading directories and writing to a MySQL table in PHP?

One potential pitfall when reading directories and writing to a MySQL table in PHP is the risk of SQL injection if user input is not properly sanitized. To prevent this, always use prepared statements when interacting with the database. Additionally, be cautious when reading directories to ensure that only the necessary files are accessed to prevent security vulnerabilities.

// Example of using prepared statements to write to a MySQL table safely
$pdo = new PDO("mysql:host=localhost;dbname=mydatabase", "username", "password");

$stmt = $pdo->prepare("INSERT INTO mytable (column1, column2) VALUES (:value1, :value2)");

$value1 = $_POST['value1'];
$value2 = $_POST['value2'];

$stmt->bindParam(':value1', $value1);
$stmt->bindParam(':value2', $value2);

$stmt->execute();