Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

wfoster

macrumors 6502a
Original poster
Feb 16, 2009
696
38
Plymouth, UK
http://wfoster.co.uk/talk.php

Is it because it cannot connect to the database? I have a mySQL DB, not sure if my sql.php file has the right information in? This is my sql.php file:

Code:
<?
$mysql_host = "localhost";
$mysql_database = "web231-wfoster";
$mysql_user = "web231-wfoster";
$mysql_password = "************";
$MyDB = "web231-wfoster";

$dieMysqlMessage = 'Could not connect to database.<br />';

if(!mysql_connect($MySqlhostname, $MySqlusername, $MySqlpassword,  $MyDB))
{
	die($dieMysqlMessage . mysql_error());
}
		
$con = mysql_connect($MySqhostname, $MySqlusername, $MySqlpassword);
mysql_select_db($MyDB, $con);
?>

Is it correct or how can I find out all my information for it? (Yes, I'm new to coding).

Thanks
 
You don't seem to be making use of your variables there. Also you need <?php, not just <?. Try this,
PHP:
<?php
$mysql_host = "localhost";
$mysql_database = "web231-wfoster";
$mysql_user = "web231-wfoster";
$mysql_password = "************";

$con = mysql_connect( $mysql_host, $mysql_user, $mysql_password ) or
  die ("Error connecting: ". mysql_error());
mysql_select_db( $mysql_database, $con ) or
  die ("Error selecting DB: ". mysql_error());
?>
If it doesn't you should get one of the error messages.
 
http://wfoster.co.uk/talk.php

Is it because it cannot connect to the database? I have a mySQL DB, not sure if my sql.php file has the right information in? This is my sql.php file:

Code:
<?
$mysql_host = "localhost";
$mysql_database = "web231-wfoster";
$mysql_user = "web231-wfoster";
$mysql_password = "************";
$MyDB = "web231-wfoster";

$dieMysqlMessage = 'Could not connect to database.<br />';

if(!mysql_connect($MySqlhostname, $MySqlusername, $MySqlpassword,  $MyDB))
{
    die($dieMysqlMessage . mysql_error());
}
        
$con = mysql_connect($MySqhostname, $MySqlusername, $MySqlpassword);
mysql_select_db($MyDB, $con);
?>
Is it correct or how can I find out all my information for it? (Yes, I'm new to coding).

Thanks

Variable names are case sensitive.
 
PHP:
<?php

$mysql_host = "localhost";
$mysql_database = "web231-wfoster";
$mysql_user = "web231-wfoster";
$mysql_password = "************"; // your actual password 

$con = mysql_connect($mysql_host, $mysql_user, $mysql_password) 
           or die ("Could not connect to database.<br />Error: " . mysql_error());
mysql_select_db($mysql_database, $con)
           or die ("Could not select the database.");

?>

Untested but fixed code based on responses above including some consolidation on my part (i.e. why define a variable to hold text for the die function when you can include it in the function itself?) to streamline your code. As you learn more about coding, that's one of my golden rules - less code is better than more code to accomplish the same task. Makes for faster runtime and easier debugging, when possible of course.

-jim
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.