Board Index > Php Help > Databases > Error Message

Jaycee
jaycee
Member
Posts: 2
Joined: 31-12-69
Error Message

Hi,

I have created a simple HTML form and I'm trying to send the details to a MySQL DB when I click submit. I have created the following:

However when I click submit on my form page I get the following message.

Error: Access denied for user 'root'@'localhost' (using password: YES)

Do I need to define the password in order to access the MySQL database? Can I avoid this? Either way, how do I proceed?

Cheers,

John

Posted on January 5th, 2010

Jaycee
jaycee
Member
Posts: 2
Joined: 31-12-69
Error Message

Sorry, my current code is

<?php
$Name = $_POST['FName'];
$Surname = $_POST['LName'];
$Comment = $_POST['Comment'];
$PName = $_POST['PFname'];
$PSurname = $_POST['PLname'];
$Year = $_POST['Year'];
$Contact = $_POST['Contact'];
$House = $_POST['HOuse'];



mysql_connect ("localhost","root","DBNAME") or die ('Error: ' . mysql_error());
mysql_select_db ("HOH");

$query="INSERT INTO entries (House, Name, Surname, Comment, Pupil_Name, Pupil_Surname, Year, Contact_No)VALUES ('".$House."', '".$Name."', '".$Surname."', '".$Comment."''".$PName."', '".$PSurname."', '".$Year."', '".$Contact."')";

mysql_query($query) or die (mysql_error());

ECHO "<meta http-equiv=\"refresh\" content=\"3; url=http:">";

?>


Posted on January 5th, 2010

Dave
dave
Administrator
Posts: 3
Joined: 31-12-69
Error Message

yes you need to supply the host, username and password to connec to the database.

which it looks like your are doing, double check make sure your using the right username and password.

Posted on January 5th, 2010

Dave is my name

Dave
dave
Administrator
Posts: 3
Joined: 31-12-69
Error Message

Just for clarification here's I would connect to the database simple define your values then connect to the server then select the database you want to use:

define('DBHOST','localhost');
define('DBUSER','username');
define('DBPASS','password');
define('DBNAME','database name');


// make a connection to mysql here
@$conn = mysql_connect (DBHOST, DBUSER, DBPASS);
@$conn = mysql_select_db (DBNAME);
if(!$conn){
	die( "Sorry! There seems to be a problem connecting to our database.");
}


Posted on January 5th, 2010

Dave is my name

Login to post a reply