SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Hybrid View

  1. #1
    SitePoint Evangelist
    Join Date
    Jun 2000
    Location
    England
    Posts
    587
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK I am upto the bit where i am trying to pull stuff from a sql db for the first time I might add...

    heres the script..

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

    <head>
    <body>

    <?php
    // Connect to the database server

    $dbcnx = mysql_connect("localhost", "cloughie", "mypass");

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

    }

    //select the jokes database

    if (! @mysql_select_db("dbname") ) {
    echo( "<p> Unable to locate the Joke database at this time.</p>" );
    exit();

    }
    ?>

    <p>Here are 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 enquiry : " .
    mysql_error() . "</p>!);
    exit();
    }


    // Display the text of each joke in a paragraph
    while ( $row = mysql_fetch_array($result) ) {
    echo("<P>" . $row["JokeText"] . "</P>");
    }

    ?>

    This is the bit it is failing on... In particular line 47 the echo line... any ideas ? ?

    I get the message "parse error"

    cheers in advance...

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

  2. #2
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Replace the bold text with this:

    // Display the text of each joke in a paragraph
    while ($row = mysql_fetch_array($result)) {
    $JokeText = $row["JokeText"];
    echo("<P>$JokeText</P>");
    }

    See the bold line? If you want to add another field to the results, simply add another line like that with the field names changed.

    Hope this helps!


  3. #3
    SitePoint Evangelist
    Join Date
    Jun 2000
    Location
    England
    Posts
    587
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    cheers, but when i do that I get this error ?

    Parse error: parse error, expecting `STRING' or `NUM_STRING' or `'$'' in /home/cloughie/wannabebig-www/php/php.php on line 47


    hhmmmmm...
    Wannabebig Bodybuilding
    Wannabebig Bodybuilding Forums - Wanna be bigger and stronger?
    At Large Nutrition - nutritional supplements

  4. #4
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmmm: could you paste the file here and highly line 47?

  5. #5
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I hate to ask this, but are you sure you have data in the database, because you are testing for if (!$result) And then even if your db table contains no records that would pass. try
    if (mysql_num_rows($result) > 0) {
    // Display the text of each joke in a paragraph
    while ( $row = mysql_fetch_array($result) ) {
    print '<P>' . $row["JokeText"] . '</P>';
    }
    }
    else {
    print "Sorry No records found!";
    }





    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  6. #6
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cloughie upon further checking I found your problem and it lies here
    if (!$result) {
    echo("<p>Error performing enquiry : " .
    mysql_error() . "</p>!);
    exit();
    }

    You are missing a double quote on the following line
    mysql_error() . "</p>!);
    should be
    mysql_error() . "</p>!";
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

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

    Freddie : yeah i relaised that and kciked myself hard for a long time after realising !!!!!!

    Cheers

    Cloughie
    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
  •