Jump to content

cant connect to database....


jwk811

Recommended Posts

Warning: mysql_connect(): Can't connect to MySQL server on 'mysqladmin2.secureserver.net' (111) in /home/content/j/w/k/jwk811/html/db.php on line 10
Unable to connect to database! Please try again later.

And heres my db.php file. Can you tell me what I'm doing wrong?
[code]<?php
//Connect To Database
$hostname="mysqladmin2.secureserver.net:43998";
$username="091381";
$password="(mypassword";
$dbname="091381";
$usertable="users";
$yourfield = "uderid";

mysql_connect($hostname,$username, $password) OR DIE ("Unable to connect to database! Please try again later.");
mysql_select_db($dbname);

$query = "SELECT * FROM $usertable";
$result = mysql_query($query);
if($result) {
    while($row = mysql_fetch_array($result)){
        $name = $row["$yourfield"];
        echo "Name: ".$name;
    }
}
?> [/code]

I can see that the die part is coming up in the script. What would make it do that? I think there might be something wrong with the hostname.. I'm using phpMYadmin does that look like the right thing for host?
Link to comment
Share on other sites

Verify the following:

$hostname="mysqladmin2.secureserver.net:43998";
$username="091381";
$password="(mypassword";

Your problem lies in either hostname, username, or password. The port number in the hostname seems very odd, usually MySQL is never run on such a high port, try it without the port numbers, so:

$hostname="mysqladmin2.secureserver.net";
Link to comment
Share on other sites

yeah i think i already tried that.. ill try again and see what happens tho, thanks. and i had another questions.. you know with the membership thing in a database.. this code to connect is asking for one field in the table.. dont i want the whole table?
Link to comment
Share on other sites

[code]<?php
//Connect To Database
$hostname="mysqladmin2.secureserver.net:43998";
$username="091381";
$password="(mypassword";
$dbname="091381";
$usertable="users";
$yourfield = "uderid";

mysql_connect($hostname,$username, $password);
mysql_select_db($dbname);
echo mysql_error();
$query = "SELECT * FROM $usertable";
$result = mysql_query($query);
if($result) {
// stuff here
}
?> [/code]
try that, just with stuff here put your other stuff.

Also double check your password, double check your username, replace that connection address with "localhost" and see if that works.
If none of that works, then what is the url of your web hosting company.
Link to comment
Share on other sites

okay i tried that new code and got a bunch of warning saying cant connect to database and cant find a link to connect to server. i think it might have something to do with the password because when i used a fake password to see what would happen the same warnings came up about the connecting but im sure i didnt type in what i thought it was to be wrong. im using the same pasword that i use to log into my database or my account on phpmyadmin right? And ive tried a lot to find out why i cant connect and i still dont know what to do. is there anyone out there that could try it out for me? and see what the problem is and if its just me or whatever. ive had this same problem a while ago about not connecting and gave up for a while because i just couldnt find out what the problem was. thanks for the help!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.