开发者

PHP MySQL authentication error

开发者 https://www.devze.com 2023-02-13 06:32 出处:网络
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 foll

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_clo开发者_开发知识库se($conn);

}

?>


Password for user root is incorrect.

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

$dbpass = '';


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.

  • mysqladmin
  • User Creation
  • Granting Privileges
  • Setting Passwords


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消