SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2000
    Location
    Rocky Mount, NC
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    having trouble...

    I have no clue what's wrong with this script. It says it can't find the database and I don't know why. Here is the script.

    PHP Code:
    <?
    $dbcnx 
    = @mysql_connect("localhost","username","password");
    mysql_select_db("mostover_songs"$dbcnx);


    $result mysql_query("SELECT songID,songName,songArtist,songRequest FROM songs ORDER BY songRequest DESC LIMIT 0,5");

    If (!
    $result) {  
     echo(
    "<P>Error performing query: " .
           
    mysql_error() . "</P>");
    }

    while (
    $row mysql_fetch_array($result)) {
     
    $songName $row["songName"];
     
    $songArtist $row["songArtist"];
     
    $songRequest $row["songRequest"];
     
    $songID $row["songID"];
     echo(
    "<li><a href=\"topsongs.php?name=$songName\"><b>$songName</b></a> by <a href=\"topsongs.php?artist=$songArtist\"><b>$songArtist</b></a>");
    }

    ?>
    Stuart Briscar Consulting - Free Website Consulting

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Sorry, but this one gave me pause to chuckle.

    $dbcnx = @mysql_connect("localhost","username","password");

    You have to enter your username in place of "username" and you have to enter your password in place of "password". For instance:

    $dbcnx = @mysql_connect("localhost","JoeSmith","magic4");

    If you didn't set up a username and password do this:

    $dbcnx = @mysql_connect("localhost","","");

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2000
    Location
    Rocky Mount, NC
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, yeah I know that. Sorry, I should've mentioned that I only have it as that so I don't have to put the real info there.
    Stuart Briscar Consulting - Free Website Consulting

  4. #4
    SitePoint Addict kunal's Avatar
    Join Date
    Oct 2000
    Posts
    307
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this may sound like a stupid question, but does the database exist?
    i dunno...

  5. #5
    SitePoint Enthusiast
    Join Date
    May 2000
    Location
    Rocky Mount, NC
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, the database exist. I've checked all the obvious several times.
    Stuart Briscar Consulting - Free Website Consulting

  6. #6
    SitePoint Addict kunal's Avatar
    Join Date
    Oct 2000
    Posts
    307
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @mysql_select_db("mostover_songs", $dbcnx);


    try this...
    i dunno...

  7. #7
    SitePoint Enthusiast
    Join Date
    May 2000
    Location
    Rocky Mount, NC
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm. Didn't change anything but I'm sure I needed the @ in the code. I e-mailed the admin to check and see if there is anything wrong with the mySQL.

    After the script says "No Databases Selected" it tells me there is an error on the line where the WHILE statement starts.
    Stuart Briscar Consulting - Free Website Consulting

  8. #8
    SitePoint Zealot
    Join Date
    Nov 2000
    Posts
    164
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you have a server running on you machine, Like apache or iis, or is it running on an external server and you are either getting it for free or paying.

    If you have someone else hosting the webpages for you, then you should probably change the location of your database from localhost to whatever the server is.

  9. #9
    SitePoint Enthusiast
    Join Date
    May 2000
    Location
    Rocky Mount, NC
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My friend who owns a server is giving some space to work on my site before it opens.

    Do you suggest I change the localhost to the IP of the server or my site or the .com of the server or my site?
    Stuart Briscar Consulting - Free Website Consulting

  10. #10
    SitePoint Addict Percipient's Avatar
    Join Date
    Jun 2000
    Location
    Summerland, BC, Canada.
    Posts
    226
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Some hosts, perhaps most, only support the use of "localhost". Depending on where you intend your site to be when it goes live, you may have a problem with anything else.
    Ed Rands

  11. #11
    What's HTML?
    Join Date
    May 2001
    Location
    San Diego, CA
    Posts
    1,701
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't see where using "localhost" in the database connection line would be a problem unless your PHP script is on a different server then the MySQL database. Ask your friend if MySQL is on the same server that you are hosting your pages.

    But from the results you're receiving, it sounds like you're connecting to MySQL fine. I would guess there's something wrong with the database itself.

    Have you ever been able to connect to your database before? Through another script or telnet.
    Ryan Kuhle - A Proud Advisor - Got Questions? Just Ask!
    Get your website started for less than $20! Click Here

  12. #12
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One thing I've never understood is why do people do this:

    $dbcnx = @mysql_connect("localhost","username","password");
    mysql_select_db("mostover_songs", $dbcnx);


    When you can just do

    $dbcnx = mysql_connect("localhost","username","password");
    mysql_select_db("mostover_songs");

    Try that, other all the code looks fine, the database error should have come earlier....

    Try:

    $num = mysql_numrows($query);
    print $num;

    put that straight after the query

    if it causes an error do

    $num = mysql_numrows();
    print $num;

  13. #13
    SitePoint Zealot
    Join Date
    Nov 2000
    Posts
    164
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is in reply to my old message, I use to have f2s host my content, and I had to specify where the database was located, I couldn't supply localhost.


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
  •