Results 1 to 5 of 5

Thread: mysql database error....

  1. #1
    Join Date
    May 2008
    Posts
    93
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default mysql database error....

    Hey guys, I'm trying to make a text based game, and I need some help, I tried setting up a mysql database, and tried to connect to it with this code,
    PHP Code:
    <?php

    $mysql_host 
    "edited out";
    $mysql_database "edited out";
    $mysql_user "edited out";
    $mysql_password "edited out";

    $con mysql_connect($mysql_database,$mysql_host,$mysql_user,$mysql_password);
    mysql_select_db($mysql_database,$mysql_host);
    if (!
    $con)
    {
          die(
    mysql_error());
    } else {
            if (!
    mysql_select_db($Mysql_database,$mysql_user,$mysql_password))
            {
                  echo 
    "Worked!";
            }
    }
    ?>
    and here is what I get...
    PHP Code:
    Warningmysql_connect() [function.mysql-connect]: Access denied for user 'mysql3.000webhos'@'server15.000webhost.com' (using passwordYESin /home/a4605859/public_html/cfg.php on line 9

    Free Web Hosting

    PHP Error Message

    Warning
    mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /home/a4605859/public_html/cfg.php on line 10

    Free Web Hosting
    Access denied 
    for user 'mysql3.000webhos'@'server15.000webhost.com' (using passwordYES
    Please help as soon as possible

  2. #2
    Join Date
    Feb 2007
    Location
    Toronto, Ontario, Canada
    Posts
    586
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quite simply, your username and/or password is wrong.
    Reading quickly from your site (000webhosting.com), your user should be of the form: username_dbname, like: stephen_database1. You seem to have 'mysql3.000webhos' as your user (judging from the warning output).
    -AGENT

  3. #3
    Join Date
    Aug 2008
    Posts
    20
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Try this:

    PHP Code:
    <?php 

    $mysql_host 
    "localhost"
    $mysql_database "db"
    $mysql_user "user"
    $mysql_password "pass"

    $con mysql_connect($mysql_host ,$mysql_user$mysql_password); 
    mysql_select_db($mysql_database); 
    if (!
    $con

          die(
    mysql_error()); 

    else

          echo 
    'Connected';

    ?>
    Your db connection line was not okay, and you did the following:

    You checked if the connection died with (!$con)
    That was okay, but after the else you typed a if (there is a elseif function)
    But that is not the biggest fault, you checked after the else again if the connection died, you had a '!' before it..

    If you script php, first brainstorm if the script won't work

    If it still doesn't work, contact me
    Last edited by Justcheat; 03-21-2009 at 11:04 AM.

  4. #4
    Join Date
    Feb 2006
    Location
    Amsterdam
    Posts
    13,692
    Mentioned
    146 Post(s)
    Quoted
    130 Post(s)

    Default

    php Code:
    <?php

    $mysql_host = "edited out";
    $mysql_database = "edited out";
    $mysql_user = "edited out";
    $mysql_password = "edited out";

    //mysql_connect doesn't take mysql_database as argument. (Read the PHP Manual.)
    $con = mysql_connect($mysql_host,$mysql_user,$mysql_password);

    // This might be interesting too (saves you that extra check):
    // $con = mysql_connect($mysql_host,$mysql_user,$mysql_password) or die(mysql_error());

    //mysql_select_db($mysql_database,$mysql_host);
    // No need to select it twice.
    if (!$con)
    {
          die(mysql_error());
    } else {
            //mysql_select_db takes one argument, and one optional argument.
            //you also used an uppercase M for the var. PHP's var's are case sensitive.
            if(mysql_select_db($mysql_database) {
                echo 'Worked';
            }
            /*if (!mysql_select_db($Mysql_database,$mysql_user,$mysql_password))
            {
                  echo "Worked!";
            }*/

            // do stuff here.


            // don't forget to close your connection.
            mysql_close($con);
    }
    ?>
    Last edited by Wizzup?; 03-21-2009 at 12:59 PM.



    The best way to contact me is by email, which you can find on my website: http://wizzup.org
    I also get email notifications of private messages, though.

    Simba (on Twitter | Group on Villavu | Website | Stable/Unstable releases
    Documentation | Source | Simba Bug Tracker on Github and Villavu )


    My (Blog | Website)

  5. #5
    Join Date
    Feb 2009
    Location
    Nebraska
    Posts
    68
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Perhaps almost totally off-topic, but if you are interested in writing text-based games, first be sure you are familiar with Inform 7.
    Grippy has approximately 30,000 hours of Delphi coding experience. srsly.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. DTM Database
    By Dervish in forum Research & Development Lounge
    Replies: 40
    Last Post: 09-10-2009, 11:46 PM
  2. Online Database
    By Simtoon in forum Web Development
    Replies: 6
    Last Post: 02-03-2009, 11:41 PM
  3. BMP database?
    By tank phobia in forum SRL Site Discussion
    Replies: 52
    Last Post: 10-06-2008, 09:27 PM
  4. MySQL connection error?
    By Abyssal in forum Web Development
    Replies: 6
    Last Post: 06-07-2007, 04:52 AM

Posting Permissions

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