mysql - error with connecting to database using authentication in php -
the errors are:
could not connect mysql: access denied user 'zebrahead'@'localhost' (using password: yes)
- warning: mysql_connect(): access denied user 'zebrahead'@'localhost' (using password: yes) in c:\wamp\www\testsite\authentication.php on line 12
db_user using computer's name.
authentication.php
<?php $authorized = false; if ((isset($_server['php_auth_user']) , isset($_server['php_auth_pw']))) { define ('db_user','zebrahead'); define ('db_password','password'); define ('db_host','localhost'); define ('db_name','registration'); $dbc = mysql_connect (db_host,db_user,db_password) or die ('could not connect mysql: '.mysql_error()); mysql_select_db (db_name) or die ('could not select database: '.mysql_error()); $query ="select first_name users username='{$_server['php_auth_user']}' , password=password('{$_server['php_auth_pw']}')"; $result = mysql_query($query); $row=mysql_fetch_array ($result); if ($row) { $authorized = true; } } if(!$authorized) { header('www-authenticate: basic realm="my website"'); header ('http/1.0 401 unauthorized'); } ?>
index.php
<?php require_once('authentication.php'); ?> <html> <head></head> <body> if ($authorized) { echo "<p>please enter valid username , password!</p>"; } else { echo "<p>you have been authenticated!</p>"; } ?> </body> </html>
check privilege of user , give grand privilege
Comments
Post a Comment