What are some potential pitfalls when using SQL queries in PHP to search for specific data in a database?

One potential pitfall when using SQL queries in PHP is SQL injection attacks, where malicious code is injected into the query to manipulate the database. To prevent this, you should always use prepared statements with parameterized queries to sanitize user input.

// Example of using prepared statements to prevent SQL injection

// Assume $searchTerm is the user input to search for in the database
$searchTerm = $_POST['searchTerm'];

// Prepare the SQL query with a placeholder for the search term
$stmt = $pdo->prepare("SELECT * FROM table WHERE column = :searchTerm");

// Bind the search term to the placeholder
$stmt->bindParam(':searchTerm', $searchTerm);

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

// Fetch the results
$results = $stmt->fetchAll();