What is the potential issue with using mysql_real_escape_string on a POST field in PHP?

Using mysql_real_escape_string on a POST field in PHP can potentially lead to SQL injection vulnerabilities if not used correctly. It is recommended to use prepared statements with parameterized queries instead, as they provide a more secure way to interact with the database.

// Connect to the database
$mysqli = new mysqli("localhost", "username", "password", "database");

// Check connection
if ($mysqli->connect_error) {
    die("Connection failed: " . $mysqli->connect_error);
}

// Prepare a SQL statement with a parameterized query
$stmt = $mysqli->prepare("INSERT INTO table_name (column1, column2) VALUES (?, ?)");

// Bind parameters
$stmt->bind_param("ss", $_POST['field1'], $_POST['field2']);

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

// Close the statement and connection
$stmt->close();
$mysqli->close();