+ Reply to Thread
Results 1 to 4 of 4

Thread: mysql_connect error

  1. #1
    rajat44 is offline Banned rajat44 is an unknown quantity at this point
    Join Date
    Oct 2010
    Posts
    24

    Question mysql_connect error

    i'm creating a register script for my site and till yesterday it was working fine and i could take registrations.. now all it shows is:

    Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'urworld'@'10.33.248.75' (using password: YES) in /home/urworld/public_html/config.php on line 10
    cannot connect to server

    The config.php file where i have the connection to the mysql serves goes like this:

    <?

    $host="localhost"; // Host name
    $username="myusername"; // Mysql username
    $password="mypassword"; // Mysql password
    $db_name="database name"; // Database name
    $tbl_name="table name"; // Table name

    //Connect to server and select database.
    mysql_connect("$host", "username", "password")or die("cannot connect to server");

    mysql_select_db("database name")or die("connot find db");

    ?>



    Please can someone please please help?

    the url of the page which shows error on clicking submit is:

    UrWorld/Register

    Thank You..

  2. #2
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: mysql_connect error

    MySQL usernames should be your cpanel username, followed by an underscore, followed by the name you created in cPanel. The above username ("urworld") thus looks incorrect.

    The "Access denied for user" error has been covered in many threads. Search the forums to look for solutions to your problem. You just might learn a few things you weren't expecting.

    The old mysql driver is outdated and has been supplanted twice over. You should update your code to use the new PDO driver. If you need a tutorial, try "Writing MySQL Scripts with PHP and PDO".

    Please use [php], [html] or [code] tags (as appropriate) to delineate and format code.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  3. #3
    bdistler's Avatar
    bdistler is offline x10 Lieutenant bdistler is an unknown quantity at this point
    Join Date
    May 2010
    Location
    Catalina AZ USA
    Posts
    349

    Re: mysql_connect error

    Enter your user stuff then try this PHP code on your server...

    PHP Code:
    <?php
    // THIS IS A TEST PHP SCRIPT TO TEST CONNECTING TO YOUR MySQL DATABASE
    // DO NOT INCORPORATE INTO YOUR SITE UNTIL YOU HANDLE ERRORS AND 'PASSWORD' TYPE DATA in THE APPROPRIATE WAY
    //
    // was tested on servers skyy, and bour at x10hosting
    //
    // Make sure any PHP files have permissions set to 0644 (NOT 0666 or 0777) and subdirectories set to 0755
    //
    // There is a possibility your .htaccess file can cause problems
    // some .htaccess directives that work on other sites do not work on x10Hosting 'free' sites
    // cPanel's "IP Deny Manager" on x10Hosting 'free' sites makes the wrong code
    //
    // Some say x10hosting server boru is haunted.
    //

    $serverName "localhost"// MySQL server name
    $user_name "myCpanelName_databaseUsername"// MySQL user name _ do not forget the underscore
    $password "myDatabasePassword"// MySQL password
    $db_name "myCpanelName_databaseName"// MySQL Database name - do not forget the underscore
    $tableName "tableName"// MySQL Table name

    // try get "MySQL link identifier"
    $dbConn mysql_connect($serverName$user_name$password) or die("Cannot connect to server<br />\n MySQL error ==>" mysql_errno() . "<== : ==>" mysql_error() . "<== <br />\n");
    print 
    "Connected to MySQL server successfully<br />\n";

    // try connect to database
    mysql_select_db($db_name$dbConn) or die("Cannot connect to database<br />\n MySQL error ==>" mysql_errno($dbConn) . "<== : ==>" mysql_error($dbConn) . "<== <br />\n");
    print 
    "Connected to database successfully<br />\n";

    // try to get info from table
    $query 'SELECT * FROM ' $tableName ' LIMIT 0, 1';
    $result mysql_query($query$dbConn) or die("Cannot select anything from table<br />\n MySQL error ==>" mysql_errno($dbConn) . "<== : ==>" mysql_error($dbConn) . "<== <br />\n");

    print 
    "I connected to your server, connected to your database, and received info from your table<br />\n";
    ?>
    Last edited by bdistler; 11-09-2010 at 04:18 PM. Reason: update script

  4. #4
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: mysql_connect error

    rajat44, some warnings, should you be tempted to incorporate bdistler's script into your site (rather than using it as a one-off to test connecting to MySQL): you shouldn't use die when outputting HTML. You should also handle errors at the appropriate point, which isn't often when the error is detected. Better to hand off the error (exceptions were made for just this purpose).

    Only admins should get to see the output of mysql_error, as it discloses too much information.

    In short, the techniques in bdistler's script are all right for debugging (which is what the script is for) if you don't have any other way, but shouldn't be used in production code, not even as temporary measures.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

+ Reply to Thread

Similar Threads

  1. mysql_connect() gives error Access denied
    By sles_forum in forum Free Hosting
    Replies: 1
    Last Post: 07-01-2010, 07:14 AM
  2. Error : Warning: mysql_connect()
    By mohshow in forum Free Hosting
    Replies: 3
    Last Post: 06-21-2010, 03:20 PM
  3. mysql_connect()
    By masterofkings in forum Programming Help
    Replies: 0
    Last Post: 05-15-2010, 06:57 AM
  4. pb with mysql_connect
    By fomalhaut in forum Programming Help
    Replies: 6
    Last Post: 09-18-2009, 08:03 AM
  5. Please help me on mysql_connect
    By sirSam in forum Programming Help
    Replies: 24
    Last Post: 02-17-2009, 01:38 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers