What are the potential pitfalls of using mysqli_real_escape_string for handling NULL values in PHP MySQL queries?

Using mysqli_real_escape_string for handling NULL values in PHP MySQL queries can lead to unexpected behavior as the function returns an empty string when given a NULL value. To properly handle NULL values, you can check if the value is NULL and use the appropriate SQL syntax to insert a NULL value into the database.

// Assuming $conn is your mysqli connection object
$value = ($input_value !== null) ? mysqli_real_escape_string($conn, $input_value) : 'NULL';
$sql = "INSERT INTO table_name (column_name) VALUES ($value)";
mysqli_query($conn, $sql);