What function can be used to escape potentially dangerous characters when inserting data into the database?

To escape potentially dangerous characters when inserting data into the database, you can use the mysqli_real_escape_string function in PHP. This function helps prevent SQL injection attacks by escaping special characters in a string before sending it to the database.

// Establish a connection to the database
$connection = mysqli_connect("localhost", "username", "password", "database");

// Escape potentially dangerous characters before inserting data into the database
$data = mysqli_real_escape_string($connection, $data);

// Insert the escaped data into the database
$query = "INSERT INTO table_name (column_name) VALUES ('$data')";
mysqli_query($connection, $query);