SalientAnimal Posted March 18, 2013 Share Posted March 18, 2013 Hi All, I am stuck at the very first part of my site, and have no idea why I and getting the below error message. I have tried recreating the user in the mysql database with the correct username and password, and even granted full access. I am setting up a site and jsut created an initial default account to test everything is working fine, so din't mind sharing usernames and passwords if need be as I am currently setting up the webserver on a local machine just to test before launching it. Username: test Password: W@t3r Table: test Database: maindb Warning: mysqli_connect() [function.mysqli-connect]: (28000/1045): Access denied for user 'test'@'localhost' (using password: YES) in C:\xampp\htdocs\the_lab\labupload.php on line 8MySQL connection failed: Access denied for user 'test'@'localhost' (using password: YES) Here the initial part of my code, I am using it to upload files into my database: <?php // Check if a file has been uploaded if(isset($_FILES['uploaded_file'])) { // Make sure the file was sent without errors if($_FILES['uploaded_file']['error'] == 0) { // Connect to the database $dbLink = mysqli_connect("localhost","test","W@t3r","maindb"); if(mysqli_connect_errno()) { die("MySQL connection failed: ". mysqli_connect_error()); } // Gather all required data $name = $dbLink->real_escape_string($_FILES['uploaded_file']['name']); $mime = $dbLink->real_escape_string($_FILES['uploaded_file']['type']); $data = $dbLink->real_escape_string(file_get_contents($_FILES ['uploaded_file']['tmp_name'])); $size = intval($_FILES['uploaded_file']['size']); // Create the SQL query $query = " INSERT INTO `test` ( `name`, `mime`, `size`, `data`, `created` ) VALUES ( '{$name}', '{$mime}', {$size}, '{$data}', NOW() )"; // Execute the query $result = $dbLink->query($query); // Check if it was successfull if($result) { echo 'Success! Your file was successfully added!'; } else { echo 'Error! Failed to insert the file' . "<pre>{$dbLink->error}</pre>"; } } else { echo 'An error accured while the file was being uploaded. ' . 'Error code: '. intval($_FILES['uploaded_file']['error']); } // Close the mysql connection $dbLink->close(); } else { echo 'Error! A file was not sent!'; } // Echo a link back to the main page echo '<p>Click <a href="the_lab.html">here</a> to go back</p>'; ?> I am using Apache, and Windows 7. Quote Link to comment https://forums.phpfreaks.com/topic/275812-access-denied-for-user/ Share on other sites More sharing options...
AyKay47 Posted March 18, 2013 Share Posted March 18, 2013 My guess would be the "@" symbol in the password is throwing it off. I don't know the specifics of what exactly causes this, but there has been bug report(s) on it. Try changing the password for that user to a simple string and see if that works. Quote Link to comment https://forums.phpfreaks.com/topic/275812-access-denied-for-user/#findComment-1419329 Share on other sites More sharing options...
Maq Posted March 18, 2013 Share Posted March 18, 2013 Can you manually connect via command line? Quote Link to comment https://forums.phpfreaks.com/topic/275812-access-denied-for-user/#findComment-1419333 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.