Unable to display the data in MySql table.

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
sgeorge
Forum Newbie
Posts: 2
Joined: Mon Jun 06, 2005 3:44 pm

Unable to display the data in MySql table.

Post by sgeorge »

Hi,

This is my first time here.
I have installed PHP 5 and MySql Server 4.1.
My web server is Apache web server and I tried connecting to MySql database.
using the following PHP code.


Code: Select all

#################################################
# Purpose: DB connection test script
# Author : JG
# Date   : 05/16/2005
#
#################################################

<html>
<head>
<title>
 Hello world,
</title>
<head>
<body>

<?php

$username="root";
$password="***";
$database="ectdb";

$link = @mysql_connect(localhost, $username, $password)
   or die('Could not connect: ' . mysql_error());
echo 'Connected successfully';
mysql_select_db($database) or die('Could not select database');

mysql_close();
echo "Database created";

?>
</body>
</html>
I am getting the following message:
################################################# # Purpose: DB connection test script # Author : JG # Date : 05/16/2005 # #################################################
Could anyone please tell me why I am not getting the "echo 'Connected successfully';" message.

Thanks in advance,
SGeorge.

JCART | Please use

Code: Select all

tags when posting php code. Review [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color][/size]

[color=green][size=75]JCART | removed password [/size][/color]
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

not sure if this is your only problem, but you need to quote localhost in mysql_connect:

ie:

Code: Select all

mysql_connect("localhost",$username,$password)
  or die(mysql_error());
sgeorge
Forum Newbie
Posts: 2
Joined: Mon Jun 06, 2005 3:44 pm

Tried but did not work

Post by sgeorge »

I tried that but it did not solve my problem.
Thanks,
sgeorge.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

try this you should...tell you any errors it finds it will:

Code: Select all

<?php 
error_reporting(E_ALL);
$username="root";
$password="***";
$database="ectdb"; 
mysql_connect("localhost", $username, $password)   
	or die('Could not connect: ' . mysql_error());
mysql_select_db($database)
	or die('Could not select database' . mysql_error());
?>

<html>
<head>
<title> Hello world,</title>
<head>
<body> 


</body>
</html>
edit: hope that is your real password I do not 8O

JCART | removed password
Post Reply