Web server wont provide ip address

the code isnt mine, but it seems it comes from a good source. When i upload the code, it just stays at 'Connecting to 'ssid'', but doesnt provide the ip address or allow me to connect to it. ive made a web server before and it did work, so there shouldnt be a problem with the esp32 im using.
i havent put the entire code, just whats related to starting the webserver. ps im very new to this

#include <WiFi.h>
#include <WebServer.h>

const char* ssid     = "--";
const char* password = "--";

WebServer server(80);
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected.");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());

skip some code

  server.begin();

you need to enter the SSID and password of your local WiFi network - it may then connect

no i did, i just removed it for the post haha

if it connects to your WiFi OK the above should print the IP address which you can enter into the web browser URL

the problem tho is that it isnt connecting. it just stays at "Connecting to (ssid)"

either the SSID or password is incorrect or you are not in range of the WiFi

are you running an ESP32 - if so try File>Examples>WiFi>WiFiScan which will display the SSIDs of networks in range

Is it a 5GHz wifi router? Or 2.4GHz?

Which model ESP32 are you using?

since ive done it correctly before, im assuming 2.4GHz. using a doit esp32 devkit v1

it doesnt exist and thats what im trying to figure out why

if I run your code on anESP32

#include <WiFi.h>

const char* ssid     = "XXXXXX";
const char* password = "zzzzz";

void setup() {
  Serial.begin(115200);
  delay(2000);
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected.");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());

}

void loop() {}

the serial monitor displays

Connecting to XXXXXX
....
WiFi connected.
IP address: 
192.168.1.227

@SurferTim makes a good point - you may have problems connecting to a 5GHz network
my network is 2.4GHz and 5GHz -the ESP32 is using 2.4GHz

I have a dual band router that transmits 2 ssids. One is 2.4GHz, and the other is 5 GHz.

so i guess its just on my end, ill try to figure out what to do. i appreciate your help

so just checked, my router is 2.4GHz

I almost always use the same esp32 you have for experiments or testing sketches here so that is a good choice. You need to be 100% sure you spelled the SSID and password exactly the same and that there are no unprintable characters.

Maybe the best thing to do is remove any password fro the router and change the SSID to something very simple like MYROUTER. If that works, try adding the old password back to the router and the sketch If that works change the ssid in both the router and the sketch. If that fails the SSID or password may be too lon, keep them below 30 characters.

okay so i made it work, thanks a lot. i had just made a dumb mistake haha

Tell us what it was so others may learn then mark the post that told you that as the solution.

I added a custom ssid and password by accident instead of my actual internet. I had done something similar like that in a previous attempt so I had assumed it would work. If my English isn’t clear I mean i added my actual internet info for it to work