SgtBeano Posted April 8, 2008 Share Posted April 8, 2008 Hi all, long time reader, first time poster (had to register too ), hoping for some help with this. I want to simply connect to a database which I've made and I can't even get the first [print] command of my PHP code to run. I've done this dozens of times and my mind cannot work out why this isn't working, I'm a moron, please help: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>| DB-Connect |</title> </head> <body> <?php print("Debug: Attempting connection...../n/n"); $user = "######"; $pass = "######"; $db = "######"; $link = @mysql_connect("localhost",$user,$pass); if(!$link) { die("Couldn't connect to database: ".mysql_error()); } print("<h2>Successfully connected to server</h2>\n\n"); @mysql_select_db($db); or die ("Couldn't open the database - $db; ".mysql_error()); print("Sucessfully selected database $db<br />\n"); mysql_close($link); ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
friedemann_bach Posted April 8, 2008 Share Posted April 8, 2008 Try omitting the '@' before 'mysql_connect' and 'mysql_select_db' to get the error messages. Maybe that gives you the right hint. Otherwise, please post the error message. Hope it helps! Quote Link to comment Share on other sites More sharing options...
SgtBeano Posted April 8, 2008 Author Share Posted April 8, 2008 Thanks tried this before with no change, but the weird thing is I don't get any error messages, just a blank page ??? Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted April 8, 2008 Share Posted April 8, 2008 A blank page generally indicates that there are errors, but you have display_errors turned to off. While you are learning and testing, I would recommend turning it on in your php.ini The error in this page is an unnecessary semi colon on this line: @mysql_select_db($db); or die ("Couldn't open the database - $db; ".mysql_error()); It should read: @mysql_select_db($db) or die ("Couldn't open the database - $db; ".mysql_error()); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.