What are the potential pitfalls of using addslashes() in PHP scripts for data manipulation?

Using addslashes() can potentially lead to SQL injection vulnerabilities if not used correctly. It is recommended to use prepared statements with parameterized queries to prevent this issue. Prepared statements separate the SQL query from the user input, ensuring that data is properly escaped and sanitized before being executed.

// Using prepared statements to prevent SQL injection
$pdo = new PDO("mysql:host=localhost;dbname=myDB", $username, $password);

$stmt = $pdo->prepare('SELECT * FROM users WHERE username = :username');
$stmt->bindParam(':username', $username);
$stmt->execute();

$result = $stmt->fetch();