SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Member
    Join Date
    Oct 2013
    Posts
    6
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Access denied for user

    Hello all,

    I am fairly new to PHP and have been frustrated over the past few days trying to resolve a Access deinied to user a3668500@localhost (using password: NO). Im using mysql_connect and my sql_query. I know they have been depricated and plan on converting to mysqli but I I would really like to figure out my current issue first.

    Here is my php code which established a connection.
    PHP Code:
    public function connect() {
            require_once 
    'include/config.php';
            
    // connecting to mysql
            
    $con mysql_connect("mysql13.000webhost.com""a3668500_mbrooks""xxxxxxxxx""a3668500_android");
                
    mysql_select_db("a3668500_android"$con);
                    
    //return database handler
            
    return $con;

    And here is my query code. It is telling me that the error comes from mysql_query line but I from what I understand its probably because Im not properly forming a connection.

    PHP Code:
    public function isUserExisted($email) { 
            
    $query "SELECT email from users WHERE email = '$email'";
            
    $result mysql_query($query);
            
    $no_of_rows mysql_num_rows($result);
            echo 
    mysql_error();
            if (
    $no_of_rows 0) {
                
    // user existed
                
    return true;
            } else {
                
    // user not existed
                
    return false;
            }


  2. #2
    SitePoint Member
    Join Date
    Oct 2013
    Posts
    6
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Is it possible that I could receive this error if there is a problem with my table or one of it's fileds? On another note, does anyone have any good recommendations for a php debugger? Right now, I am just using the error messages that I am getting in the android LogCat of eclipse.

  3. #3
    SitePoint Addict bronze trophy
    Join Date
    Sep 2005
    Posts
    323
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    " Access deinied to user a3668500@localhost (using password: NO)." means you aren't inputting a password when trying to connect. Have you checked your variable names and values properly?

  4. #4
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,068
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    Also please be aware that the mysql_* extension is now deprecated as of the current version of PHP and will very likely be removed from the next 5.x version and will likely not be in PHP 6.x (when it eventually is released). You should migrate over to either the mysqli_* extension or to PDO. PDO is a better choice as it doesn't tie you down so much to a particular database server software.

    Once you have migrated you should use Prepared Statements to prevent SQL Injection attacks. Have a read of this article from the PHP manual, it shows how to use prepared statements with PDO and also explains the principle.
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  5. #5
    SitePoint Addict bronze trophy Hall of Famer's Avatar
    Join Date
    Apr 2013
    Location
    Ithaca
    Posts
    368
    Mentioned
    6 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by SpacePhoenix View Post
    Also please be aware that the mysql_* extension is now deprecated as of the current version of PHP and will very likely be removed from the next 5.x version and will likely not be in PHP 6.x (when it eventually is released). You should migrate over to either the mysqli_* extension or to PDO. PDO is a better choice as it doesn't tie you down so much to a particular database server software.

    Once you have migrated you should use Prepared Statements to prevent SQL Injection attacks. Have a read of this article from the PHP manual, it shows how to use prepared statements with PDO and also explains the principle.
    Ditto to this, I wonder why there so many people posting their code written with the old fashined mysql functions. Use MySQLi and PDO is the way of future, I doubt many of them are working on legacy code though.

  6. #6
    SitePoint Member
    Join Date
    Oct 2013
    Posts
    6
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    As soon as I can get this error figured out, I will switch over to to pdo and prepared statements. I know the error is telling me that there is no password being sent to when trying to login. Just to make sure it was not a screw up with a variable name, I put the password directly in the mysql_connect function. My above example is not correct that. Those are the parameters for mysqli. Here is the connection call Im using.
    PHP Code:
    // Connecting to Database
        
    public function connect() {
            require_once 
    'include/config.php';
            
    // connecting to mysql
            
    $con mysql_connect("mysql13.000webhost.com""a3668500_mbrooks""xxxxxxxxxx");
                
    mysql_select_db("a3668500_android"$con);
                    
    //return database handler
            
    return $con;
        } 

  7. #7
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,068
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Hall of Famer View Post
    Ditto to this, I wonder why there so many people posting their code written with the old fashined mysql functions. Use MySQLi and PDO is the way of future, I doubt many of them are working on legacy code though.
    Probably a good few are adapting code from tutorials, some of them tutorials may have been around on the net for a good few years and might not necessarily have been updated.

    @mbrooks78 ; Load up phpMyAdmin and click on the "Users" tab. Click on the Edit Privileges link for the "a3668500_mbrooks" user and check that they have the privilges for accessing the "a3668500_android" database and check that the password for the ""a3668500_mbrooks" user matches the password that you're using in your code.
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  8. #8
    SitePoint Member
    Join Date
    Oct 2013
    Posts
    6
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    @SpacePhoenix I have a users tab but It just brings me to the table. I do not see an option for editing privilages. Here is a screen shot of what it looks like.

    mysql.png

  9. #9
    SitePoint Member
    Join Date
    Oct 2013
    Posts
    6
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Im using free hosting through 000webhost and I recently found out that they restrict remote sql connectins for free acounts. Could this be my problem?

  10. #10
    SitePoint Addict bronze trophy Hall of Famer's Avatar
    Join Date
    Apr 2013
    Location
    Ithaca
    Posts
    368
    Mentioned
    6 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by mbrooks78 View Post
    Im using free hosting through 000webhost and I recently found out that they restrict remote sql connectins for free acounts. Could this be my problem?
    It could be, but how much traffic/bandwidth does your site use? If you do not receive a lot of visitors this shouldnt be a problem.

  11. #11
    SitePoint Member
    Join Date
    Oct 2013
    Posts
    6
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    They do not allow remote connections and the sql server isnt for a website at the moment. It is for an android app that Im working on which would need to create accounts and login through the webserver and sql.

  12. #12
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,068
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by mbrooks78 View Post
    Im using free hosting through 000webhost and I recently found out that they restrict remote sql connectins for free acounts. Could this be my problem?
    Quote Originally Posted by mbrooks78 View Post
    They do not allow remote connections and the sql server isnt for a website at the moment. It is for an android app that Im working on which would need to create accounts and login through the webserver and sql.
    As your on a free hosting, the hosting company has probably locked down MySQL so it's very doubtful that you'll be able to edit user privileges. If you're still developing the site/app then you could download and install Apache, MySQL and PHP locally for developing and testing until you're ready for beta testing. You can get them individually or "canned" together using XAMP, LAMP or WAMP
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •