-2

I am trying to create a login system but each time I try to log in with my username and password these messages come up:

Warning: mysql_connect(): Access denied for user 'root'@'localhost' (using password: YES) in C:\xampp\htdocs\myfiles\connect.php on line 2

Fatal error: Call to undefined function mysql_connect_db() in C:\xampp\htdocs\myfiles\connect.php on line 3

This is all of the code I have in my connect.php file and I can see nothing wrong with it:

<?php
mysql_connect("localhost", "root", "password");
mysql_connect_db("cdcol");
?>
aksu
  • 5,221
  • 5
  • 24
  • 39
Roy Smith
  • 1
  • 1
  • 2
  • 1
    Have you confirmed your login and password are correct? – John Conde Jan 29 '14 at 19:44
  • 2
    Your access credentials are incorrect, and `mysql_connect_db()` does not exits. Did you mean `mysql_select_db`? Also, the `mysql` extension is _deprecated_. Don't use it for new code. – Wrikken Jan 29 '14 at 19:46
  • 1
    Since it clearly appears that you are just learning, do yourself a favor a learn mysqli or PDO and not the deprecated mysql extension. To your question, it seems clear from the error message that the DB is not accepting your MySQL login. Also that you are using a function that does not exist. – Mike Brant Jan 29 '14 at 19:46

1 Answers1

2

Either username or password is incorrect

By default password is set to null so try this

mysql_connect("localhost", "root", "");

If this still doesn't work then reset your password see these links for that

reset root password with wrong mysql config

MySQL/phpMyAdmin Reset ROOT PASSWORD?

Community
  • 1
  • 1
Hamza
  • 1,593
  • 2
  • 19
  • 31
  • Thanks, that worked but now only this error is appearing: Fatal error: Call to undefined function mysql_connect_db() in C:\xampp\htdocs\myfiles\connect.php on line 3 – Roy Smith Jan 29 '14 at 19:58
  • I will recommend you to use mysqli instead of mysql. Replace both lines with mysqli_connect("localhost","root","","cdcol"); – Hamza Jan 29 '14 at 20:02
  • If it has worked for you then "Tick" this answer. Thanks – Hamza Jan 29 '14 at 20:16