alsaclayan Posted March 26, 2012 Share Posted March 26, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/259726-access-denied-for-user-localhost-to-database-crystalair/ Share on other sites More sharing options...
ecabrera Posted March 26, 2012 Share Posted March 26, 2012 lets see the code Quote Link to comment https://forums.phpfreaks.com/topic/259726-access-denied-for-user-localhost-to-database-crystalair/#findComment-1331142 Share on other sites More sharing options...
alsaclayan Posted March 26, 2012 Author Share Posted March 26, 2012 Thanks for replying! Attached the code. "services.php" is where the form is. The "database.php" is where the connection is. 17879_.php 17880_.php Quote Link to comment https://forums.phpfreaks.com/topic/259726-access-denied-for-user-localhost-to-database-crystalair/#findComment-1331143 Share on other sites More sharing options...
ecabrera Posted March 26, 2012 Share Posted March 26, 2012 put this on top of your code error_reporting(E_ALL); ini_set('display_errors', '1'); Quote Link to comment https://forums.phpfreaks.com/topic/259726-access-denied-for-user-localhost-to-database-crystalair/#findComment-1331145 Share on other sites More sharing options...
alsaclayan Posted March 26, 2012 Author Share Posted March 26, 2012 Added the code on top of services.php and database.php. When I submit the form, I'm just getting "Access denied for user ''@'localhost' to database 'crystalair'", nothing else. Hmmmm. Quote Link to comment https://forums.phpfreaks.com/topic/259726-access-denied-for-user-localhost-to-database-crystalair/#findComment-1331146 Share on other sites More sharing options...
ecabrera Posted March 26, 2012 Share Posted March 26, 2012 check your database.php and check if you have all the correct names and when you use a mysql query use ` not ' Quote Link to comment https://forums.phpfreaks.com/topic/259726-access-denied-for-user-localhost-to-database-crystalair/#findComment-1331148 Share on other sites More sharing options...
alsaclayan Posted March 26, 2012 Author Share Posted March 26, 2012 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'". Quote Link to comment https://forums.phpfreaks.com/topic/259726-access-denied-for-user-localhost-to-database-crystalair/#findComment-1331151 Share on other sites More sharing options...
alsaclayan Posted March 26, 2012 Author Share Posted March 26, 2012 I forgot to mention. My database.php returns "Successfully connected to database." The problem must be with my query. Hmmmm. Quote Link to comment https://forums.phpfreaks.com/topic/259726-access-denied-for-user-localhost-to-database-crystalair/#findComment-1331152 Share on other sites More sharing options...
ecabrera Posted March 26, 2012 Share Posted March 26, 2012 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` )"; Quote Link to comment https://forums.phpfreaks.com/topic/259726-access-denied-for-user-localhost-to-database-crystalair/#findComment-1331154 Share on other sites More sharing options...
alsaclayan Posted March 26, 2012 Author Share Posted March 26, 2012 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' )"; Quote Link to comment https://forums.phpfreaks.com/topic/259726-access-denied-for-user-localhost-to-database-crystalair/#findComment-1331158 Share on other sites More sharing options...
ecabrera Posted March 26, 2012 Share Posted March 26, 2012 glad i could help remember use ` becuase ' dont work must of the time Quote Link to comment https://forums.phpfreaks.com/topic/259726-access-denied-for-user-localhost-to-database-crystalair/#findComment-1331160 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.