How can the error "Incorrect table definition; there can be only one auto column and it must be defined as a key" be resolved when creating MySQL tables with PHP queries?

The error "Incorrect table definition; there can be only one auto column and it must be defined as a key" occurs when trying to create a table with multiple auto-increment columns without defining any of them as a primary key. To resolve this issue, you need to designate one of the auto-increment columns as the primary key.

// Define your MySQL query with the correct table structure
$query = "CREATE TABLE example_table (
    id INT AUTO_INCREMENT PRIMARY KEY,
    other_column VARCHAR(50),
    another_column INT AUTO_INCREMENT
)";

// Execute the query
$result = mysqli_query($connection, $query);

// Check if the query was successful
if ($result) {
    echo "Table created successfully.";
} else {
    echo "Error creating table: " . mysqli_error($connection);
}