Click here to Skip to main content
15,909,242 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Fatal error: Uncaught mysqli_sql_exception: Access denied for user 'username'@'localhost' (using password: YES) in E:\New folder\htdocs\Online Property Sales System\Src\html\register.php:10 Stack trace: #0 E:\New folder\htdocs\Online Property Sales System\Src\html\register.php(10): mysqli->__construct('localhost', 'username', 'password', 'Property_Lanka') #1 {main} thrown in E:\New folder\htdocs\Online Property Sales System\Src\html\register.php on line 10


What I have tried:

<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "Property_Lanka";

// Create connection
$conn = new mysqli('localhost','root','','Property_Lanka');
// Check connection
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}

$sql = "INSERT INTO MyGuests (`fname`, `lname`, `Pass`, `mno`, `dob`, `email`)
VALUES('$fname','$lname','$pass','$mno','$dob','$email')";

if ($conn->query($sql) === TRUE) {
  echo "New record created successfully";
} else {
  echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
?>
Posted
Updated 10-May-22 7:40am
Comments
CHill60 10-May-22 10:47am    
either your username or your password is incorrect or username does not have insert permissions on your database
Richard Deeming 10-May-22 10:51am    
Assuming those values will eventually come from the user, your code is vulnerable to SQL Injection[^]. NEVER use string concatenation/interpolation to build a SQL query. ALWAYS use a parameterized query.
PHP: SQL Injection - Manual[^]
PHP: Prepared statements and stored procedures - Manual[^]
Richard Deeming 10-May-22 10:52am    
You are also preparing to store users' passwords in plain text. Don't do that!
Secure Password Authentication Explained Simply[^]
Salted Password Hashing - Doing it Right[^]

PHP even has built-in functions to help you do the right thing:
PHP: password_hash[^]
PHP: password_verify[^]

1 solution

"Access denied" for a folder means just that: the Database engine cannot access the file (or some part of the folder tree leading to it) because it is not owned by the engine user.

MySql (and SQL Server) does not u=run under a "normal" user account - there is a specific user account under which it runs as it starts before any real user is even logged in.
When you tell it to access folders outside "it's user" the engine user must be given the appropriate access permissions, which does not happen by default for "proper" user accounts.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900