Results 1 to 2 of 2
  1. #1
    Join Date
    May 2004
    Posts
    2

    Unanswered: phpmyadmin-mysql "No Database Selected"

    I am a newbie trying to conect my webpage (index.php) to a MySQL database. I am using myphpadmin for editing and have configured the necessary file but I cannot connect. I get "No Database Selected" on the webpage. This is the code for index.php.
    Can anyone tell by this if I am doing something wrong? The host, user, password and db name have been ommitted for this posting..

    <?PHP
    error_reporting(E_ALL^E_NOTICE);
    //insert mysql_connect(); and mysql_select_db(); calls here
    // make connection to database
    $hostName = "localhost";
    $userName = "user";
    $password = "pass";
    $dbName = "dbName";

    // make connection to database
    mysql_connect($hostName, $userName, $password) or die("Unable to connect to host $hostName");

    $date = '<select name="date">';
    $agency = '<select name="agency">';
    $city = '<select name="city">';

    $result = mysql_query("SELECT date,agency,city FROM agencies") or die(mysql_error());
    while($row = mysql_fetch_array($result))
    {
    $date .= '<option value="'.$row["date"].'>'.$row["date"].'</option>';
    $agency .= '<option value="'.$row["agency"].'>'.$row["agency"].'</option>';
    $city .= '<option value="'.$row["city"].'>'.$row["city"].'</option>';
    }
    $date .= '</select>';
    $agency .= '</select>';
    $city .= '</select>';
    /*removed echo lines,this would just give you the dropdowns at the top of the page for no real reason */
    ?>

  2. #2
    Join Date
    Apr 2004
    Location
    Europe->Sweden->Stockholm
    Posts
    71
    Do one of the following:

    In your SELECT, name the database explicitly.
    Example: SELECT something FROM database.table WHERE condition.

    OR

    Use the PHP function mysql_select_db("database", $dbconnection) to specify the database you wish to use for your queries.

Posting Permissions

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