SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: help for newbie

  1. #1
    SitePoint Member
    Join Date
    Jun 2001
    Location
    Australia
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    help for newbie

    I am trying to follow the tutorial on creating a website with MySQL and PHP.

    I can get all the MySQL commands from the command line right ie select database etc, but when I try to use this code

    if (! @mysql_select_db("jokes") ) {
    echo( "<P>Unable to locate the jokes " .
    "database at this time.</P>" );
    exit();[

    I get the error message "Unable...." even though I have successfully connected to the server.

    I am running redhat 7.1, Apache 1.3.20, PHP 4.0.6, MySQL 3.23.39.

    Any help pointing me in the right direction would be greatly appreciated.

    Tarka

  2. #2
    SitePoint Addict manipura's Avatar
    Join Date
    Apr 2001
    Location
    Calgary,AB
    Posts
    345
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: help for newbie

    Originally posted by tarka

    if (! @mysql_select_db("jokes") ) {
    echo( "<P>Unable to locate the jokes " .
    "database at this time.</P>" );
    exit();[

    Tarka

    I think you have to put the connection in the select_db.

    $db = mysql_connect("host", "username", "password");

    if (! @mysql_select_db("jokes",$db) ) {

  3. #3
    SitePoint Member
    Join Date
    Jun 2001
    Location
    Australia
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Stilll cant connect

    This is the code I have used

    <HTML>
    <HEAD>
    <TITLE> Our List of Jokes </TITLE>
    <HEAD>
    <BODY>
    <?php

    // Connect to the database server
    $dbcnx = @mysql_connect("localhost",
    "", "");
    if (!$dbcnx) {
    echo( "<P>Unable to connect to the " .
    "database server at this time.</P>" );
    exit();
    }

    // Select the jokes database
    if (! @mysql_select_db("jokes", $dbcnx) ) {
    echo( "<P>Unable to locate the jokes " .
    "database at this time.</P>" );
    exit();
    }


    but still can not connect to the jokes database.


    Tarka

  4. #4
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Re: help for newbie

    Originally posted by manipura
    I think you have to put the connection in the select_db.
    no. if only one connection's open it's used.

  5. #5
    Node mutilating coot timnz's Avatar
    Join Date
    Feb 2001
    Location
    New Zealand
    Posts
    516
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you need to put at least a username for localhost, ie root, I'm not sure though. However, if it can't connect it should have said so with an error.

    Remove the @ from infront of mysql_select_db(), and print mysql_error() as well, as that would shed some light onto the problem.

    And also, don't quote me on this one, will it still select the database if you have it in an if statement, ie, should it not be:

    $selection = mysql_select_db("jokes", $dbcnx);

    if (!$selection) {
    echo (mysql_error());
    exit();
    }

    I'm not sure though, please correct me.


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
  •