SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist
    Join Date
    Jun 2000
    Location
    England
    Posts
    587
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Stuck on PHP/SQL tutorial

    its driving me crazy and its only the first task

    OK here isthe code I copied from the Article..

    PHP Code:
    <html>
    <head>
    <title>Our list of Jokes</title>
    </head>

    <body>

    <?php

    //connnect to the database server
    $dbcnx = @mysql_connect("localhost""user""pass");

    if (!
    $dbcnx) {
        echo( 
    "<p>Unable to connect to the " .
            
    "database server at this time.</p>" );
        exit();

    }

    //select the jokes database
    if (! @mysql_selct_db("db_name") ) {
        echo( 
    "<p>Unable to connect to the " .
            
    "Joke Database at this time.</p>" );
        exit();

    }

    ?>


    <p>Here are all the Jokes in our database: </p>

    <blockquote>

    <?php

    //Request the text of all the jokes
    $result mysql_query(
        
    "SELECT JokeText from Jokes");
    if (!
    $result)  {
        echo(
    "<p>Error performing query: " .
            
    mysql_error() . "<p>");
        exit();
    }

    //Display the text of each joke in the paragraph 
    While ( $row mysql_fetch_array($result) ) {
        echo(
    "<p>" $row["JokeText"] . "<p>");

    }

    ?>

    </blockquote>

    </body>

    </html>


    It bsaically gives me nothing and this in the view source

    <html>
    <head>
    <title>Our list of Jokes</title>
    </head>

    <body>

    So I think well I will copy the actual code straight from Kevins tutorial on the web and place my db cnx' on there..

    The at least I get the follwing on the view source

    <HTML><HEAD><TITLE> Our List of Jokes </TITLE><HEAD><BODY><P> Here are all the jokes in our database: </P><BLOCKQUOTE>
    </BLOCKQUOTE></BODY></HTML>


    Still not what I want I have 2 jokes in my db

    can someone help
    Wannabebig Bodybuilding
    Wannabebig Bodybuilding Forums - Wanna be bigger and stronger?
    At Large Nutrition - nutritional supplements

  2. #2
    SitePoint Member atem451's Avatar
    Join Date
    May 2001
    Location
    Berlin
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have an error in your syntax on line 21.

    its:

    @mysql_select_db("db_name")

    *NOT*

    @mysql_selct_db("db_name")


    Footbag: Spread the Spirit

  3. #3
    SitePoint Addict kunal's Avatar
    Join Date
    Oct 2000
    Posts
    307
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmm.. are you sure about the column names?? mysql is case sensitive...
    i dunno...

  4. #4
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Copy the sql statement you have in your code. Go to your console and fire up the mysql server. Then run the query from the console and see if you get any results. If not, the problem is that your database doesn't have the data or schema you think it does. If you get the desired results from the command line, then the problem is with the syntax in your code.

    Also, when debugging turn error reporting on in your code. The @ before the function calls, such as @mysql_connect turns off error reporting. Remove the @ for debugging purposes and any errors will be sent in the HTML source that ends up at the browser. When you have successfully debugged you can turn error reporting back off again by prefixing with the @.
    Last edited by freakysid; Jun 13, 2001 at 08:35.

  5. #5
    SitePoint Evangelist
    Join Date
    Jun 2000
    Location
    England
    Posts
    587
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks guys

    atem you are right thats what the problem was...

    I even got a hold of Kevin and hassled him up

    I gotta learn to type slower
    Wannabebig Bodybuilding
    Wannabebig Bodybuilding Forums - Wanna be bigger and stronger?
    At Large Nutrition - nutritional supplements


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
  •