Before you give up on the passcode
Try the passcodes you might have used, slowly, and stop if the phone starts making you wait between attempts. An iPhone can be set to erase itself after ten wrong attempts.
Check whether the phone was backed up: to iCloud for an iPhone, or to the Google account for an Android phone. Photos, contacts and messages may be there even if the phone itself stays locked.
Why a reset is the wrong first step
Apple’s and Google’s routes for a forgotten passcode reset the phone. That gives you a working phone back, but it deletes what was stored on it. Use them only once you are sure the data is not needed or is safe in a backup.