Jump to content

Access denied for user ''@'localhost' to database 'crystalair'


alsaclayan

Recommended Posts

Hi everyone! I'm getting the error "Access denied for user ''@'localhost' to database 'crystalair'" (crystalair is the name of my database) whenever I submit my form which inserts a new row to the database table "order". The same happens when I try to retrieve data from the table using select query.

 

However, I can successfully perform operations (select, insert) in my other pages which involves another database table "user". If this is a connection error, how can I successfully perform operations with another table? Also, my connection query does not return an error. I have also checked to make sure my user has been granted "All Privileges" in the phpmyadmin. I've run out of ideas. Can you please help? Thanks a lot.

I changed my connection query into:

 

$connection = mysqli_connect('localhost', 'admin', 'admin123', 'crystalair');
if ($connection->connect_errno) {
echo "Failed to connect to MySQL: (" . $connection->connect_errno . ") " . $connection->connect_error;
} else {
echo "Successfully connected to database.";

 

And changed my insert query into:

 

$query = "INSERT INTO `crystalair`.`order` (`orderNo` , `name` ,`email` ,`phone` ,`schedule` ,`waiting` ,`make` ,`model` ,`year` ,`plate` ,`color` ,`services` ,`cost`)
		  VALUES (`$no`, `$name`, `$email`, `$phone`, `$schedule`, `$waiting`, `$make`, `$model`, `$year`, `$plate`, `$color`,  `$service`, `$cost`
		  )";

 

And I'm still getting "Access denied for user ''@'localhost' to database 'crystalair'".

try

 

$query = "INSERT INTO `crystalair`,`order` (`orderNo` , `name` ,`email` ,`phone` ,`schedule` ,`waiting` ,`make` ,`model` ,`year` ,`plate` ,`color` ,`services` ,`cost`)

  VALUES (`$no`, `$name`, `$email`, `$phone`, `$schedule`, `$waiting`, `$make`, `$model`, `$year`, `$plate`, `$color`,  `$service`, `$cost`

  )";

Thank you! I got it to work! I changed the query code into:

 

$query = "INSERT INTO `crystalair`.`order` (`orderNo` , `name` ,`email` ,`phone` ,`schedule` ,`waiting` ,`make` ,`model` ,`year` ,`plate` ,`color` ,`services` ,`cost`)
		  VALUES ('$no', '$name', '$email', '$phone', '$schedule', '$waiting', '$make', '$model', '$year', '$plate', '$color',  '$service', '$cost'
		  )";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.