Page 1 of 1

You'd think I've never written a prog. before...

Posted: Thu Jun 03, 2004 9:20 pm
by URWhatUXpress
I can't seem to figure out what is getting fouled up here. Assume the following:

1. All spelling is correct.

2. The database does indeed exist.

What, then, could possibly be wrong with this code:

Code: Select all

if (!($connection = mysql_connect($hostname, $username, $password)))
				{
						die("Cannot connect to Dannyprose Database.");
				} else {
					//Select Dannyprose Database
					echo "Connection Complete" . "<br>";
					if (!(mysql_select_db("ansdannyprosecom")));
					&#123;
						echo "<b>" . "Failure to connect to DANNYPROSECOM." . "</b>";
					&#125;
I'm getting a successful connect to the server, but not to the database. Now, maybe I am just missing something stupid, but this seems correct to me.

Thank you very much for any help and advice.

| dp |

Posted: Thu Jun 03, 2004 11:08 pm
by andre_c
your mysql_select_db should be

Code: Select all

<?
if (!(mysql_select_db("ansdannyprosecom", $connection)));
?>

Posted: Fri Jun 04, 2004 3:31 am
by choppsta
I'm not sure, but I think the connection identifier is optional. I think the reason it wasn't working is the ";" at the end of your if line. It should look something like this...

Code: Select all

<?php
if (!($connection = mysql_connect($hostname, $username, $password))) { 
	die("Cannot connect to Dannyprose Database."); 
} 
else { 
	//Select Dannyprose Database 
	echo "Connection Complete<br>"; 
	if (!(mysql_select_db("ansdannyprosecom", $connection))) { 
		echo "<b>Failure to connect to DANNYPROSECOM.</b>"; 
	}
}
?>
On a personal note, that's why I like to format my code with the opening brace on the same line, I find it easier to spot errors like that... (but that's just my opinion ;))