1

I have created an html form (demo.html) & POST it's value to a php file (demo1.php). Then i created database in MySQL & wrote connection code in the php file (demo1.php) but it gives the following error

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'root'@'localhost' (using password: YES) in C:\xampp\htdocs\demo1.php on line 8 Error connecting to mysql

<?php
// contact to database
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'password';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
//$conn = mysql_connect("localhost","root","password") or die ('Error connecting to mysql');

$dbname = 'test';
mysql_select_db($dbname,$conn);

//$connect = mysql_connect("localhost", "root", "pass") or die ("Error , check your server connection.");

//mysql_select_db("test");



//Get data in local variable

$v_name=$_POST['name'];

$v_email=$_POST['email'];

$v_msg=$_POST['msg'];



// check for null values

if ($v_name==""  or $v_msg=="")

echo "All fields must be entered, hit back button and re-enter information";

else{

$query="insert into contact(name,email,msg) values('$v_name','$v_email','$v_msg')";

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

echo "Your message has been received";

mysql_close($conn);

}

?>
1
  • Is the MySQL server running? Are you sure the username and password are correct? Commented Feb 24, 2011 at 5:51

4 Answers 4

2

Password for user root is incorrect.

Default password on local (home) server is empty, so I think this can help:

$dbpass = '';
Sign up to request clarification or add additional context in comments.

Comments

1

The error is pretty explicit - the username/password combination youre using is incorrect. IF thisis a fresh install you need to set a password and/or create a new user.

Comments

0
For Local Xampp username-root password --''

<?php
// contact to database
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
?>

Comments

0

The main reason for this is that the password is wrong. Did you specify the root password when setting up xampp? If not, then leave the password blank as delphist states above

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.