SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    Non-Member
    Join Date
    Jan 2004
    Location
    Seattle
    Posts
    4,328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can't Connect to Database

    I hiave a page that I'm using to display just one cell from a MySQL table - a cell in a field that contains articles about states and nations. Let's say the page is named alaska.php, and it has a big include in the body section. The include, in turn, includes another page with the following:

    PHP Code:
    <?php
    $todayDate 
    date("m-d-Y");
    ?>
    <?php 
    require_once('../../../../Connections/World.php');
    mysql_select_db($database_World$World);
    $query_Statesarticles "SELECT statesarticles.ArticleS from statesarticles WHERE statesarticles.SCode = '{$mycode}'";
    $Statesarticles mysql_query($query_Statesarticles$World) or 
    die(
    mysql_error());
    // send it to mysql (step 2.)
    while ($row_Statesarticles mysql_fetch_assoc($Statesarticles) )
     {
    // loop throught the resulting record set and display each row (step 4.)
      
    echo $row_Statesarticles['ArticleS'];
    }
    ?>
    When I was tweaking the code, trying to get it to work, I frequently got "No Database Selected" error messages. They were often triggered when I refereshed the page; everything would work fine until I refreshed it, when I got an error message. If I refreshed it again, then everything would once again be OK.

    Finally, it was working perfectly - then I must have done something wrong, and "No Database Selected" is permanently displayed. The table is named statesarticles, and I'm selecting a cell from the ArticleS field. Any idea what I'm doing wrong?

    Also, does my code look good for my purpose? I thought I might need the "loop through" function for displaying a single cell, but I couldn't remove it without wrecking everything.

    Thanks.

  2. #2
    Non-Member
    Join Date
    Jan 2004
    Location
    Seattle
    Posts
    4,328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just stumbled across the solution, but it raises another question.

    I'm using Dreamweaver. Over on the right, I can click a + under "Applications" to see a visual representation of my database connection. When I clicked on the connection, it was empty - no tables were listed. They had been listed earlier.

    I deleted the connection, re-connected, and everything works fine now. But why would a database connection "lose" its tables in the first place? And how could I connect to databases without using Dreamweaver in the first place? When it makes a connection, I think it creates a new file, right?


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
  •