Cannot connect to database.

Ok, so first off I am a TOTAL noob at PHP. I know a bit of HTML and some css, but not much beyond that.

What I am trying to do is set up a website that will basically ping minecraft servers and get the number of players, maximum player count, whether its online, etc, and then let users vote a server up or down, and then the servers are listed according to their voted rank. I found a free code snippet to do the contacting the servers. Then, I found another free snippet to allow voting on different things.
The first part is working perfectly, but the second one is giving me problems. Whenever I click the vote button, it says “Cannot connect to database. Please try again.”

This is the page in question: blog.johnwetzelmedia.com/

and here is a zip file of all the files for this project.
blog.johnwetzelmedia.com/Server_tracking.rar

I know for sure I have the correct info put in for the database, host name, username, password, etc.
But, for some reason, I cant get the voting to work. Someone please let me if theyve got any ideas.

Afternoon,

I’ve downloaded the zip and looked at the connection file , have you tried changing your server name to localhost as most of the time i believe it is this rather than the website address.

Hello, thanks for the reply. Yes, I have tried it with ‘localhost’ instead of the actual host address, it gives the same result, with ONE small exception.

When the hostname is set to mysql.blog.johnwetzelmedia.com:
I click on the thumbs up, and it gives me the “Cannot connect” error.
I click on the tumbs down, and it does not give me an error, but the buttons “gray out” and the little ‘processing’ animation next to it just plays and plays and plays.
There is also a delay of about 1 second or so before the error pops up, while it “thinks” and tries to submit the vote.

When the host name is set to locahost:
Clicking EITHER button gives me the error, and it also comes up with the error instantly, as opposed to the 1 second delay I get with the other setting.

Is it possible there is some sort of permissions or access issue? Maybe I have everything typed in correctly, but the script is not being ‘allowed’ to connect to the database?

I always write an if statment on the connection page to test and see if there are any errors.

E.g.
[php]

If($yourconnectionVariable))
{
echo “connected”;
}else{
echo “failed”;
}
[/php]

Do the same for the database. Go to the connection page and see what messages show.
Once you have it fixed delete the if statments.

Im not really sure what you mean by this. By ‘connection page’ do you mean the page that has the buttons on it? and Im also not sure what to put for the ‘$yourconnectionVariable’

Could you explain a little more?

I have added the code at the bottom for you for testing your connection this is the file called “pulse.config.php”

add this code to it and save it and then upload to your server and then visit the page e.g.

www.yourdomian.com/pulse.config.php and it will display the messages and then you can work out whats wrong from there
.

[php]
/**
Pulse Lite Voting Script
http://s.technabled.com/PulseVote
**/
session_start();
ob_start();
error_reporting(E_ALL-E_NOTICE);

define(‘PULSE_DIR’, ‘http://blog.johnwetzelmedia.com/Pulse’); // absolute path of the dir where Pulse is; WITHOUT trailing slash

/** DATABASE CONNECTION CONFIGURATION /
define(‘HOSTNAME’, ‘mysql.blog.johnwetzelmedia.com’); // hostname of your database; it is localhost in most cases
define(‘USERNAME’, '
****’); // username of the database
define(‘PASSWORD’, ‘******’); // password for the database
define(‘DATABASE’, ‘pulse__db’); // name of the database

@mysql_connect(HOSTNAME, USERNAME, PASSWORD);
@mysql_select_db(DATABASE);

// i havent used the @mysql_connect before so ill do it the way i know and you can delete it

// this is your connection string
$connect = mysql_connect(HOSTNAME,USERNAME,PASSWORD);
// this is connecting to your database
$db_select = mysql_select_db(DATABASE, $connect);

// check if you have a connection
if($connect)
{
	echo "Connect to the server<br />";
}else{
	echo "Failed to connect to the server<br />";
}

// check the database connection
if($db_select)
{
	echo "Connect to the database<br />";
}else{
       echo "Failed to connect to the database<br />";
     }

[/php]

Ok, this is very odd. I added the code like you said, but when I go to the page, it says it is working. (It says Connect to the server. Connect to the database.)
And yet, when I click either vote button, it still gives me the error, “cannot connect to database.” 0_o
How can that be possible? First it says it CAN connect, and then I click the button and it says it cant?

Could this maybe be a problem with permissions?

im at work at the moment and cant view the fikes, but it seems to me that your either not including the connection script on the page that needs the connection (voting script) or the path to the file connection is wrong.

if there isnt an include on that page add it and see what happens

include("put the path to the file in here ");

Ive looked at the files and the config file is included in the file vote-class.php, this file is referenced on the index page. Is the index page in the root of the domain? and are all other files in a folder called Pulse?

Yes.

Strange, if you havent already stick

[php]error_reporting(E_ALL-E_NOTICE);[/php] at the top of each page and see what error messages you get. On the McServerStatus.php page you have this line
[php]
if ( $sock = @stream_socket_client(‘tcp://’.$url.’:’.$port, $errno, $errstr, 1) ) {
[/php]

It could be a problem with the port its connecting to?

Sponsor our Newsletter | Privacy Policy | Terms of Service