How can notices be prevented when using mysql_real_escape_string function for escaping user input in PHP?
When using the mysql_real_escape_string function to escape user input in PHP, notices can be prevented by checking if the connection to the database is valid before calling the function. This can be done by using the mysqli_real_escape_string function instead, which requires an active database connection to work properly.
// Check if the database connection is valid before using mysql_real_escape_string
if($conn){
$escaped_input = mysqli_real_escape_string($conn, $user_input);
} else {
// Handle the error or connection issue accordingly
}
Related questions
-
PHP quotation marks syntax error
-
SQL injection PDO prepared statements
-
unlink rmdir secure deletion