Page 1 of 1

Unable to display the data in MySql table.

Posted: Mon Jun 06, 2005 4:15 pm
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]

Posted: Mon Jun 06, 2005 4:45 pm
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());

Tried but did not work

Posted: Wed Jun 08, 2005 5:38 pm
by sgeorge
I tried that but it did not solve my problem.
Thanks,
sgeorge.

Posted: Wed Jun 08, 2005 5:47 pm
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