If you have forgotten the passcode on your iPhone, you will have to restore the device.
To restore your iPhone -- which, again, deletes all of your data (songs, photos, videos, apps, and so on) on the iPhone use the following directions. Be absolutely sure that you have backed up the content on your iPhone before restoring it.
iPhone Previously Synchronized with a Mac or PC
If you have previously synchronized your iPhone with iTunes on a Mac or Windows computer, you typically still can backup recent additions to your iPhone by connecting it to the same computer you have used before without having to enter the passcode.
After the backup, you just need to "restore" your iPhone and have the backup copied onto the iPhone with iTunes.
Apple's official instructions to restore an iPhone with iTunes are:
Connect your iPhone to your computer [that you have previously used to sync the device].
In iTunes, select the iPhone in the "Devices" list, then "Summary" at the top of the screen.
If iTunes doesn't automatically synchronize your iPhone, do so manually [and confirm that the sync and backup were successful.]
Click “Check for Update.” iTunes tells you if there is a newer version of the iPhone software available.
Click Restore. Follow the onscreen instructions to complete the restore process. When restoring, it is recommended that you [again] backup the iPhone when prompted.
When iOS Setup Assistant asks to set up your iPhone, choose "Restore from iTunes backup."
Select your device in iTunes and choose the most recent backup of your iPhone.
After this process, your iPhone should be restored with the information from its last backup, but it no longer will have the passcode enabled. It would be wise to think carefully before setting another passcode or using the passcode feature again.
iPhone Previously Backed Up with iCloud
Apple explains that "if you have Find My iPhone enabled, you can use Remote Wipe to erase the contents of your device." Likewise, "if you have been using iCloud to backup, you may be able to restore the most recent backup to reset the passcode after the device has been erased."
Apple separately explains the simple iCloud process to erase an iPhone. This is mostly intended for an iPhone that has been lost or stolen, but the portion relevant for a forgotten password is:
Sign in to iCloud with your Apple ID (the one you use with iCloud [rather than your iPhone passcode that you do not remember]), then click "Find My iPhone."
Click "All Devices," then select the iPhone you want to erase.
In the Info window, click "Erase iPhone."
Enter your Apple ID password [for confirmation]. If the device you're erasing has iOS 7 or later, enter a phone number and message. [This is intended to be displayed to anyone who may have found your iPhone if it is lost or stolen. To just erase the iPhone, it is not necessary.]
[Now] you can restore the information on the device using iCloud Backup (if backup was turned on before you erased it).
Just like the iTunes restore process, your iPhone should be restored this way via iCloud with the information from its last backup, but your iPhone no longer will have the passcode enabled. Definitely think carefully before setting another passcode.