What are the potential pitfalls of using the Order By clause in MySQL queries with PHP?

When using the Order By clause in MySQL queries with PHP, a potential pitfall is SQL injection attacks if user input is directly concatenated into the query string. To prevent this, it is important to use parameterized queries with prepared statements to sanitize user input and avoid SQL injection vulnerabilities.

// Example of using prepared statements to prevent SQL injection
$mysqli = new mysqli("localhost", "username", "password", "database");

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

$stmt = $mysqli->prepare("SELECT * FROM table_name WHERE column_name = ?");
$stmt->bind_param("s", $user_input);

$user_input = $_POST['user_input'];
$stmt->execute();

$result = $stmt->get_result();

while ($row = $result->fetch_assoc()) {
    // output data
}

$stmt->close();
$mysqli->close();