Thanks for the question. I understand you are experiencing issues with Wi-Fi connectivity on your iPhone 5. The following resource may help to resolve your issue. I have included the basic troubleshooting steps, but please see the article for advanced steps specific to your symptom.
1. Be sure you're in range of your Wi-Fi router (access point).
2. Tap Settings > Wi-Fi and turn Wi-Fi off and on. If your W-Fi setting is dimmed, follow these steps.
3. Confirm that your Wi-Fi router and cable or DSL modem are connected to power, turned on, and connected to the Internet. If not, refer to your network administrator or Internet service provider (ISP) for assistance.
5. Tap Settings > Wi-Fi and locate the Wi-Fi network to which you're connected.
6. Tap and Forget this Network.
7. Try to connect to your desired Wi-Fi network.
Note: You may need to enter your Wi-Fi password again if your network requires one.
8. Turn your Wi-Fi router off and on. If your ISP also provides cable or phone service, check with them before attempting this step to avoid interruption of service.
9. Update your device to the latest version of software.
10. Update your Wi-Fi router to the latest firmware. For AirPort Base Stations, install updates using the AirPort Utility.
You can also learn more about joining captive Wi-Fi networks (public networks):