Php error | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Php error

I copied this code online to create a forum, but when I run the code on my browser. Instead of connecting and selecting a database. It shows "cannot connect to db". Please how can I fix it. Here's the code : https://code.sololearn.com/wbHnAH4DjgOo/?ref=app

24th Oct 2020, 10:08 PM
Joseph Oritseweyinmi
Joseph Oritseweyinmi - avatar
12 Answers
+ 1
are you running a local mysql server?
24th Oct 2020, 10:13 PM
Bahhaⵣ
Bahhaⵣ - avatar
+ 1
by "running the code on my browser" did you mean you were running it on a web server on the internet or locally on your computer?
24th Oct 2020, 10:18 PM
Bahhaⵣ
Bahhaⵣ - avatar
+ 1
did you create the database and the table?
24th Oct 2020, 10:26 PM
Bahhaⵣ
Bahhaⵣ - avatar
+ 1
could be a wrong password/username or database name.
24th Oct 2020, 10:32 PM
Bahhaⵣ
Bahhaⵣ - avatar
+ 1
No I checked multiple times I think it's the script
24th Oct 2020, 10:35 PM
Joseph Oritseweyinmi
Joseph Oritseweyinmi - avatar
+ 1
24th Oct 2020, 10:38 PM
Bahhaⵣ
Bahhaⵣ - avatar
+ 1
It connects, but I think it can't the line mysqli_select_db is the problem
24th Oct 2020, 10:46 PM
Joseph Oritseweyinmi
Joseph Oritseweyinmi - avatar
+ 1
Connection: $mysqli = new mysqli("DatabaseServerName", "UserName", "Password", "DatabaseName"); All above mentioned data you can get from service provider or set yourself.
24th Oct 2020, 10:58 PM
JaScript
JaScript - avatar
+ 1
Ep Ap Wuq
25th Oct 2020, 5:27 PM
Elena IVANOVA
Elena IVANOVA - avatar
0
No, I am using 000webhost's database
24th Oct 2020, 10:16 PM
Joseph Oritseweyinmi
Joseph Oritseweyinmi - avatar
0
On a web server
24th Oct 2020, 10:20 PM
Joseph Oritseweyinmi
Joseph Oritseweyinmi - avatar
0
Yes
24th Oct 2020, 10:27 PM
Joseph Oritseweyinmi
Joseph Oritseweyinmi - avatar