SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict
    Join Date
    Jun 2004
    Location
    U.S.
    Posts
    258
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    localhost problem

    Hi folks,
    I am using the localhost as testing server, after I added the name and email, I got this error message"Unable to locate the jokedatabase at this time." not sure why the database keeps not getting any connection at all?

    I have bought a book call "Database Driven Website Using PHP & MySQL", just followed exact php code that book describes. But the error keeps me to go anywhere. So frustrated!

    Would you please help me out of this frustration? Thanks very much from the bottom of my heart!
    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>Joke CMS: Add new authors</title>
    </head>

    <body>
    <?php
    if(isset($_POST['name'])):
    //A new author has been entered
    //using the form below.

    //connecting to database
    $dbcnx = @mysql_connect('localhost','root','');
    if(!
    $dbcnx){
        exit(
    '<p>Uable to connect to the'.'database server at this time.</p>');
    }
    //selecting a database
    if(@mysql_select_db('jokegallery')){
        exit(
    '<p>Unable to locate the joke'.'database at this time.</p>');
    }        

    //starting to add a new author
    $name $_POST['name'];
    $email $_POST['email'];
    $sql "INSERT INTO author SET name='$name',email='$email'";
    if(@
    mysql_query($sql)){
        echo 
    '<p>New author added</p>';
        }else{
        echo 
    '<p>Error adding new author:'.mysql_error().'</p>';
    }
    ?>
    <p><a href="<?php echo $_SERVER['PHP_SELF']; ?>">Add another author</a></p>
    <P><a href="authors.php">Return to authors list</a><p>
    <?php else: //allow the user to enter a new author ?>

    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <P>Enter the new author:</P>
    <label>Name:<input type="text" name="name"  /></label><br />
    <label>Email:<input type="text" name="email"  /></label><br />
    <input type="submit" value="SUBMIT" />
    </form>
    <?PHP endif; ?>
    </body>
    </html>

  2. #2
    SitePoint Wizard bronze trophy Kailash Badu's Avatar
    Join Date
    Nov 2005
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    make sure there is a database with the name jokegallery in your mysql database server.

  3. #3
    SitePoint Addict
    Join Date
    Jun 2004
    Location
    U.S.
    Posts
    258
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. It is correct jokegallery.

  4. #4
    SitePoint Wizard bronze trophy Kailash Badu's Avatar
    Join Date
    Nov 2005
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The right code should be. instead of:
    PHP Code:
    //selecting a database 
    if(@mysql_select_db('jokegallery')){ 
        exit(
    '<p>Unable to locate the joke'.'database at this time.</p>'); 

    put this:
    PHP Code:
    //selecting a database 
    if(!@mysql_select_db('jokegallery')){ 
        exit(
    '<p>Unable to locate the joke'.'database at this time.</p>'); 


  5. #5
    SitePoint Evangelist superuser2's Avatar
    Join Date
    Aug 2006
    Posts
    598
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, logical error. And I wouldn't silence errors with @ during development because that's not a good idea if you need to see what's wrong. Leave those off, and then either change php.ini or use ini_set or an apache directive to turn off display_errors on your production server.

  6. #6
    SitePoint Addict
    Join Date
    Jun 2004
    Location
    U.S.
    Posts
    258
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I want to let you guys know how much I appreciate what you guys offered!

    Thanks very much.


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
  •