Results 1 to 3 of 3

Thread: php/MySQL question - Error:No database selected

  1. #1
    Join Date
    Apr 2007
    Posts
    2

    Default php/MySQL question - Error:No database selected

    Background - I am building an contest entry form to win a prize. There will be a web-based admin for my client to pick a winner each day.

    This is my first time configuring a site on Bluehost.

    What I've done so far
    - Created a database in cPanel X
    - Created a database user
    - Created necessary table(s) in phpMyAdmin

    When I test my form mysql_error() returns 'No database selected' after you submit the form.

    I am assuming I'm not connecting to the db correctly or am missing something. Right before my INSERT statement I have this code:

    Code in question
    mysql_connect("localhost", "userprefix_username", "password");
    mysql_select_db('userprefix_dbname');

    FYI - I echo'd my sql INSERT statement and tested it in phpMyAdmin and it works.

    I know this question has been asked similarly before but I couldn't get a solution from those threads. Any help appreciated.

    - Reed

  2. #2
    Join Date
    Apr 2007
    Posts
    2

    Default

    What I didn't do was add the user to the database... i had read that but i looked like I had done it, doh!

    http://helpdesk.bluehost.com/kb/inde...&root=7&id=359

  3. #3
    Join Date
    Mar 2007
    Location
    http://www.bluehostreview.org
    Posts
    1,133

    Default

    usualy helpdesk wont help in troubleshooting custom scripts.

    ...
    Code in question
    mysql_connect("localhost", "yourdatabase_username", "password");
    mysql_select_db('yourdatabasename');

    basically, open the config file that you see these lines, and include the database name. you can get a sample of script at cpanel, where you created database. the sample script is there.
    Charles Gan
    www.bluehostreview.org : Bluehost reviews hosted at bluehost:cool:

Posting Permissions

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