"Connected to wifi" just means "connected to a wireless router", it doesn't mean "connected to the internet". First, the router has to be connected to the internet (obviously). Less obviously, you
could be getting a limited connection - connection to the router, but not
through it to the internet. Why? A fixed IP address set on your phone that's wrong for the router, no DHCP slots available in the router (all your neighbors connected, leaving no slot for you - there are only 253 of them), the router isn't working ... there are a number of possibilities, and troubleshooting router connection problems is difficult enough if you're at the router - it's difficult squared doing it on a forum like this.
Read
Troubleshooting Wi-Fi Connection Problems and see if any of that fixes it.