no variables are passed to the funtion, so the function can't read those variables. You can fix this one of two ways:
1: Make the variables accessible by declaring them global in the function:
function db_connect() {
GLOBAL $hostname, $user, $pass;
// note: don't enclose variables in "quotes" unless you have to.
$link = mysql_connect($hostname, $user, $pass) or die("<center><font face='Verdana, Arial, Helvetica, sans-serif' size='2' color='FF0000'>Could not connect</font></center>");
print ("<center><font face='Verdana, Arial, Helvetica, sans-serif' size='2' color='FF0000'>Connected successfully</font></center>");
mysql_close($link);
}
2: Pass the variables to the function in the function call:
function db_connect($hostname, $user, $pass) {
$link = mysql_connect($hostname, $user, $pass) or die("<center><font face='Verdana, Arial, Helvetica, sans-serif' size='2' color='FF0000'>Could not connect</font></center>");
print ("<center><font face='Verdana, Arial, Helvetica, sans-serif' size='2' color='FF0000'>Connected successfully</font></center>");
mysql_close($link);
}
// then you would call the function like this:
db_connect($hostname, $user, $pass);
Option 2 is much cleaner and is generally the prefered method.