Jump to content

I'm Rusty (as in Iron), please help!


SgtBeano

Recommended Posts

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>

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/100135-im-rusty-as-in-iron-please-help/
Share on other sites

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());

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.