Abhijit
Abhijit

Reputation: 11

PHP MySQL authentication error

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

}

?>

Upvotes: 1

Views: 2336

Answers (4)

Gatonye
Gatonye

Reputation: 81

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

Upvotes: 0

Karthik
Karthik

Reputation: 1488

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');
?>

Upvotes: 0

prodigitalson
prodigitalson

Reputation: 60413

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.

Upvotes: 1

delphist
delphist

Reputation: 4549

Password for user root is incorrect.

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

$dbpass = '';

Upvotes: 2

Related Questions