How do I make sure the oil filter I buy is the right one for my car?

I have a honda-accord 2007

This isn't exactly rocket science. The parts store will have a reference book you can look up the correct filter number for your vehicle, or the sales clerk can look it up for you.

Auto parts store can help

Ask the autoparts store to help you. There's only one.

Take the old filter with you to the store. Compare it to the one the staff is selling you. Or you can read the reference books in the store. There are reference books in the shelves.

Give the person behind the counter the year, make and model of your car.

You don't even have to go to a parts store to find out. Any of the on line auto parts stores (NAPA, AUTOZONE, ADVANCE AUTO) have a method by which you can find out what filter/s work. Many of the primary oil filter makers also have an on line reference guide. Even Walmarts that carry oil filters have an application book. Some even have an interchange guide in the back.
First you look up the make, then the model and then if needed the engine size. But most of the time a car maker uses the same oil filter on most of their cars.

They just need to be the same color.

It's not smart or cheaper to change your own oil, in fact so many newbies have messed up their vehicle trying to play lube boy that I can't help but laugh when I hear the dumb things they do! Draining the automatic transmission by mistake is the best one! Just look for ad specials at fast lube joints or even the dealer. There's a place near me that charges $19 for an oil change. It costs me $27 for 5 quarts of oil and a filter at my commercial account prices.

Buy the same one as you take off or get the cars make model and vin number they should be able to sell you the right one