How can the issue of single quotes breaking the query be resolved in PHP?

When single quotes are used in a query in PHP, they can break the query if not handled properly. To resolve this issue, you can use the mysqli_real_escape_string function to escape any single quotes in the input before including them in the query.

// Assuming $conn is your database connection
$input = "O'Reilly"; // Example input with a single quote
$escaped_input = mysqli_real_escape_string($conn, $input);

$query = "SELECT * FROM table WHERE column = '$escaped_input'";
$result = mysqli_query($conn, $query);

// Rest of your code to handle the query result