You have to connect your iPhone to the computer.
Restart Both Devices:
Restart your computer (where your iTunes/Music library is).
Restart your iPhone/iPad. This can often clear minor glitches.
Check the USB Cable and Port:
Try a different USB cable.
Try a different USB port on your computer.
Check for Updates:
Make sure iTunes (on PC) or the Music app/macOS (on Mac) is the latest version.
Make sure your phone's iOS/iPadOS is up to date (Settings > General > Software Update).
Verify Sync Settings in iTunes/Finder:
Connect your phone to your computer.
In iTunes (or Finder on a newer Mac), select your device.
Go to the Music tab.
Make sure "Sync Music" is checked.
Check if you have selected "Entire music library" or "Selected playlists, artists, albums, and genres." If the latter, ensure the music you want is actually selected.
Click Apply or Sync.
Check "Sync Library" (if you use Apple Music or iTunes Match):
On your Phone: Go to Settings > Music and make sure "Sync Library" is turned ON.
On your Computer (if using Music app on Mac): Go to Music > Settings (or Preferences) > General and make sure "Sync Library" is checked.
On your Phone: Go to Settings > [Your Name] > Media & Purchases > Sign Out. Then sign back in.
On your Computer: In iTunes/Music app, go to Account > Sign Out. Then sign back in.
Make sure your phone has enough free storage space for the music you are trying to sync (Settings > General > iPhone/iPad Storage).