I need Help in connecting my Database

HI guys this is my first time to use 000webhost and been trying everything for almost week and still cant figure out what to place in these 3 req.
$user="WHERE WILL I GET THE LINK;
$password=“WHERE WILL I GET THE LINK”;
$database=“WHERE WILL I GET THE LINK”;
:confused::confused:

mysql_connect(localhost,$user,$password);
@mysql_select_db($database) or die( “Unable to select database”);

Thankz.

log into your member’s area, go to your account’s CPanel, click on the MySql button and add a database, once that’s done, it will show you the required info there.

you’ll need to replace the hostname, username, database name and password so be sure to change “localhost” in the mysql_connect function, aswell as the top 3.

personally, i’d change this code:


$user="WHERE WILL I GET THE LINK;
$password="WHERE WILL I GET THE LINK";
$database="WHERE WILL I GET THE LINK";

mysql_connect(localhost,$user,$password);
@mysql_select_db($database) or die( "Unable to select database");

to this code:


$user="put username here";
$password="put password here";
$database="put dbname here";
$hostname="something like mysql2.000webhost.com"

mysql_connect($hostname,$user,$password);
@mysql_select_db($database) or die( "Unable to select database");

i tried this but there is an error

$user="";<---- User of my database? or account in 000webhost?
$password="";<---- password of my database? or account in 000webhost?
$database=“a8314628_forum”;
$hostname="";<------- server name? which i can get in my account information.

mysql_connect($hostname,$user,$password);
@mysql_select_db($database) or die( “Unable to select database”);

Host ‘srv12.000webhost.com’ is not allowed to connect to this MySQL server in /home/a8314628/public_html/forum/admin.php on line 52

forget your 00wh info, when you create your database, you have to give it a name, username, and password, then you’ll see them in the page
$user="";<---- User name you entered when making the database(prefixed with “a8314628_”)
$password="";<---- password you entered when making the database
$database=“a8314628_forum”;<---- looks like you’ve got this part right
$hostname="";<---- it will be shown where i mentioned above.
click the MySql button, ALL the info is right there, if you’ve set up the db.

here’s an example only:
$user=“a8314628_something”;
$password=“password”;
$database=“a8314628_forum”;
$hostname=“mysql2.000webhost.com

it looks like you put “srv12.000webhost.com” somewhere, that’s wrong
good luck
:slight_smile:

Thank you so much got it running correctly…:slight_smile: