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

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.