SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Senior Webdesigner koolbrian's Avatar
    Join Date
    Dec 2000
    Location
    Mauritius
    Posts
    599
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    correcting a rather simple script (my first one)

    hey could somebody please tell me what's wrong with that script, it's my first, I want to make a search query in my jokes database

    PHP Code:
    <?php if ( isset($key) ): ?>
    <?php
    $results 
    mysql_query("Select Joketext from Jokes where Joketext like "%$key%"");
    echo(
    $results);
    ?>
    <?php 
    else: ?>
    <html>
    <FORM ACTION="<?php echo($PHP_SELF); ?>" METHOD=GET>
    Search: <INPUT TYPE=TEXT NAME="key"><BR>
    <INPUT TYPE=SUBMIT VALUE="GO">
    </FORM>
    </html>

    <?php endif; ?>
    What's wrong?

    Brian
    Is there a trick to discover the small error, apart from the error() function
    BrianStudio - the webdesign company
    Professional & Affordable
    Brian Dove - Senior Graphic Designer
    Direct Hire: info@brianstudio.com

  2. #2
    Senior Webdesigner koolbrian's Avatar
    Join Date
    Dec 2000
    Location
    Mauritius
    Posts
    599
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i'm i obliged to use arrays to display jokes text. ( i know it will be much better, but i would like to know if it was possible)

    like this script
    PHP Code:
    <?php
    if (! @mysql_select_db("jokes") ) {
     echo( 
    "<P>Unable to locate the joke " .
     
    "database at this time.</P>" );
     exit();
    }
    $results mysql_query("SELECT joketext from Jokes");


    echo (
    "here are all the jokes $results ");

    ?>
    doesn't make my jokes to be shown on the page!

    Brian
    BrianStudio - the webdesign company
    Professional & Affordable
    Brian Dove - Senior Graphic Designer
    Direct Hire: info@brianstudio.com

  3. #3
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <?php if ( isset($key) ): ?>
    <?php
    $results = mysql_query("Select Joketext from Jokes where Joketext like "%$key%"");
    echo($results);
    ?>
    <?php else: ?>
    <html>
    <FORM ACTION="<?php echo($PHP_SELF); ?>" METHOD=GET>
    Search: <INPUT TYPE=TEXT NAME="key"><BR>
    <INPUT TYPE=SUBMIT VALUE="GO">
    </FORM>
    </html>

    <?php endif; ?>



    Try:

    <?php
    if ( isset($key)) {
    mysql_connect("localhost", "username", "password");
    mysql_select_db("database_name");
    $results = mysql_query("Select Joketext from Jokes where Joketext like '%$key%'");
    while ($result = mysql_fetch_array($results)) {
    extract($result);
    print "$Joketext \n<br>";
    }
    } else {
    ?>
    <html>
    <FORM ACTION="<?php echo($PHP_SELF); ?>" METHOD=GET>
    Search: <INPUT TYPE=TEXT NAME="key"><BR>
    <INPUT TYPE=SUBMIT VALUE="GO">
    </FORM>
    </html>
    <?php
    }
    ?>


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
  •