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.

Link to comment
Share on other sites

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'".

Link to comment
Share on other sites

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`

  )";

Link to comment
Share on other sites

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'
		  )";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.