What are some common examples of using if statements within a mysql_query in PHP?

When using a mysql_query in PHP, you may want to include conditional logic using if statements to handle different scenarios or conditions. Common examples include checking if a certain condition is met before executing the query or determining the result of the query and taking action based on that result.

// Example of using if statements within a mysql_query in PHP
$query = "SELECT * FROM users WHERE id = 1";
$result = mysql_query($query);

if ($result) {
    // Query was successful
    while ($row = mysql_fetch_assoc($result)) {
        // Process the data
    }
} else {
    // Query failed
    echo "Error: " . mysql_error();
}