Jump to content

Recommended Posts

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 8
MySQL 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.

 

Link to comment
https://forums.phpfreaks.com/topic/275812-access-denied-for-user/
Share on other sites

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.

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.