0

I am trying to create a signup script with PHP but I keep getting the same error Connection to database failed: Access denied for user 'emoisblack'@'localhost' (using password: YES). I have definitely cross checked to see if there is any typo, and everything seems correct. Still I get the same error. I tried deleting the user, dropping the database and the connection and doing the whole process with a new connection. All to no avail. I am adding my "database connect" code to the bottom of this post and also the signup script that adds new users to the database. I hope they help. Let me please know if any thing else needs to be clarified. Thanks in advance for any assistance.

dbconnect.php

<?php $conn = mysqli_connect("localhost", "emoisblack", "", "db_obank"); if (!$conn) {
die("Connection to database failed: ".mysqli_connect_error());}

signup.php

<?php include 'dbconnect.php'; $firstname = $_POST['firstname']; lastname = $_POST['lastname']; $username = $_POST['username']; $email = $_POST['email']; $pwd = $_POST['pwd']; echo $username;
e-ba'e
  • 25
  • 4
  • Never post passwords... lol... Change your password... Anyway: can you login to the database command line? Are you sure user "emoisblack" has access to the db_obank database? Have you granted access for this user to this particular database? Try to login to mysql client with the above username and password and try to do a "USE DATABASE db_obank" and see if you succeed. If not, you need to "GRANT" permission with root. – Saskia Sep 06 '16 at 00:18
  • Haha, thanks i just copied and pasted everything. Yea "emoisblack" is granted full privileges. I am using mysql Workbench and when i try logging in with that user, it works. It just never seems to be able to connect when i use it. I just did, and I was able to connect but when i try again on the site, no bueno – e-ba'e Sep 06 '16 at 00:31
  • 1
    Absolutely, permission problem, "Access denied for user" have a look [link](http://stackoverflow.com/questions/6445917/connect-failed-access-denied-for-user-rootlocalhost-using-password-yes) – John Sep 06 '16 at 00:39
  • Are you able to login with other users on other databases on this server? For instance, when my mysql server is down, I also get access denied errors in Apache. Otherwise there has to be a typo somewhere, maybe a capital letter needed somewhere, linux is case sensitive. – Saskia Sep 06 '16 at 00:41
  • 1) AFAIK, `mysqli_connect()` will never return a *falsy* value so you can't check it with `if (!$conn)`. Use `if (mysqli_connect_error())` instead. 2) After creating your user and grants in MySQL, have you run `FLUSH PRIVILEGES;`? – Phil Sep 06 '16 at 04:30

1 Answers1

0

Well if you're 100% absolutely sure you have proper credentials, it could be that maybe it does not exist or it's configured oddly.

To find out what absolutely who's allowed in is going on, run this

SELECT user,host,plugin FROM mysql.user;

Make sure the 'plugin' is mysql_native_password, if it's not run a simple update statement on mysql.user to change it.

Dellowar
  • 3,160
  • 1
  • 18
  • 37