Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 5 of 5
  1. #1
    Senior Member DesignBox's Avatar
    Join Date
    Apr 2004
    Posts
    340
    Member #
    5659
    I am using Kevin Yank's "Build your own database driven website usin PHP & MYSQL" from sitepoint as a reference for something I am building.

    At first I had trouble connecting to the database with the following code:


    PHP Code:
    $dbcnx = @mysql_connect('localhost''username''password'); 
    if (!
    $dbcnx) { 
      exit(
    '<p>Unable to connect to the ' 
          
    'database server at this time.</p>'); 



    so I searched around and found this that seemed to work as I'm not getting any errors for it:



    PHP Code:
    mysql_connect('localhost''education''user''pass') or die(mysql_error()); 


    Now further on in the page I have this:


    PHP Code:
    $result = @mysql_query('SELECT title FROM courses'); 
                                        if (!
    $result) { 
                                        exit(
    '<p>Error performing query: ' mysql_error() . '</p>'); 
                                        } 
                                        while (
    $row mysql_fetch_array($result)) { 
                                        echo 
    '<p>' $row['title'] . '</p>'
                                        } 


    and its not working. All i get is the following message:


    Error performing query: ' . mysql_error() . '

    '); } while ($row = mysql_fetch_array($result)) { echo '

    ' . $row['title'] . '
    '; } ?>


    Any ideas on how to fix this?
    BTW, Mysql server is up and running so that's not the problem

  2.  

  3. #2
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    You need a [phpfunction]mysql_select_db[/phpfunction] before you query.
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  4. #3
    Senior Member DesignBox's Avatar
    Join Date
    Apr 2004
    Posts
    340
    Member #
    5659
    Thanks filburt,

    I edited it to this:

    PHP Code:
            <?php
    // Connect to the database server
    $dbcnx mysql_connect('localhost''education''username''password') or die(mysql_error()); 
        

    if (!@
    mysql_select_db('education')) {
    exit(
    '<p>Unable to locate the database at this time.</p>');
    }    
    ?>
    and now i receive this error(along with the previous one):

    Unable to locate the database at this time.

    '); } ?>

  5. #4
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    For your testing, don't prepend any functions with @. Otherwise you won't be able to see the errors that are occuring.
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  6. #5
    Senior Member DesignBox's Avatar
    Join Date
    Apr 2004
    Posts
    340
    Member #
    5659
    oh. thanks for that.
    The problem was that I wasn't saving the file in the proper directory for localhost but somewhere totally different.

    Silly me ....


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 03:03 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com