There are a few things that affect the focus of an image.

Starting with some inexpensive cameras, it is not unusual for them to have a minimum focus. This means that if the minimum focus is two feet and you are a foot away from the subject, your photo will not be in focus.

Another is not allowing the auto-focus mechanism in most cameras to properly cycle through. This often happens when one is in a hurry or if the batteries are nearly depleted.

Not holding the camera steady when taking the image creates problems with focus.

Finally, having the camera on 'auto' often means you cannot control the depth of field. That will result in a small portion of the subject being in focus and the rest of it out of focus. I see this a LOT.

The easiest way to rectify most of these is to use a tripod.

With a tripod, you can set the camera to aperture priority, which will allows you to adjust it for a much greater depth of field (higher f/stop number), but results in fairly long shutter settings. With the camera on a tripod, you can eliminate tripod shake, another way to induce lack of focus, by using the timer. It will also allow you to set the camera back from the subject so you are not too close.

Tripods are quite inexpensive and readily available. Even those using your phone can get an adapter to hold the phone in place of the camera. however, I have found that as good as phone cameras are in new phones, a dedicated camera will often take a much better image because a camera usually has a greater range of adjustments.

So those are the things to help with your focus. Use a tripod, set the camera on aperture priority, use the greatest f/stop available, and use the camera's timer to get a shake-free image.