SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Member
    Join Date
    Jul 2003
    Location
    scranton
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question chapt 4 Kevin Yank tutorial

    Hi couldn't find a post for this. Going through Kevin Yank tutorial. Everything worked fine for me except when deleting a joke.

    <html>
    <head>
    <title> The Internet Joke Database </title>
    </head>
    <body>
    <?php
    if (isset($_GET['addjoke'])): // If the user wants to add a joke
    ?>
    <form action="<?=$_SERVER['PHP_SELF']?>" method="post">
    <p>Type your joke herebr />
    <textarea name="joketext" rows="10" cols="40" wrap>
    </textarea><br />
    <input type="submit" name="submitjoke" value="SUBMIT" />
    </p>
    </form>
    <?php
    else: // Default page display
    // Connect to the database server
    $dbcnx = @mysql_connect('localhost', 'root', 'vnn999');
    if (!$dbcnx) {
    die( '<p>Unable to connect to the ' .
    'database server at this time.</p>' );
    }
    // Select the jokes database
    if (! @mysql_select_db('jokes') ) {
    die( '<p>Unable to locate the joke ' .
    'database at this time.</p>' );
    }
    // If a joke has been submitted,
    // add it to the database.
    if (isset($_POST['submitjoke'])) {
    $joketext = $_POST['joketext'];
    $sql = "INSERT INTO Jokes SET
    JokeText='$joketext',
    JokeDate=CURDATE()";
    if (@mysql_query($sql)) {
    echo('<p>Your joke has been added.</p>');
    } else {
    echo('<p>Error adding submitted joke: ' .
    mysql_error() . '</p>');
    }
    }
    // If a joke has been deleted,
    // remove it from the database.
    if (isset($_GET['deletejoke'])) {
    $jokeid = $_GET['deletejoke'];
    $sql = 'DELETE FROM Jokes
    WHERE ID=$jokeid';
    if (@mysql_query($sql)) {
    echo('<p>The joke has been deleted.</p>');
    } else {
    echo('<p>Error deleting joke: ' .
    mysql_error() . '</p>');
    }
    }
    echo('<p> Here are all the jokes in our database: </p>');
    // Request the ID and text of all the jokes
    $result = @mysql_query('SELECT ID, JokeText FROM Jokes');
    if (!$result) {
    die('<p>Error performing query: ' .
    mysql_error() . '</p>');
    }
    // Display the text of each joke in a paragraph
    // with a "Delete this Joke" link next to each.
    while ( $row = mysql_fetch_array($result) ) {
    $jokeid = $row['ID'];
    $joketext = $row['JokeText'];
    echo('<p>' . $joketext .
    '<a href="' . $_SERVER['PHP_SELF'] .
    '?deletejoke=' . $jokeid . '">' .
    'Delete this Joke</a></p>');
    }
    // When clicked, this link will load this page
    // with the joke submission form displayed.
    echo('<p><a href="' . $_SERVER['PHP_SELF'] .
    '?addjoke=1">Add a Joke!</a></p>');
    endif;
    ?>
    </body>
    </html>

    Error page lookes like this after delete this joke link pressed.


    Error deleting joke: Unknown column '$jokeid' in 'where clause'

    Here are all the jokes in our database:

    why did the chicken cross the road? To get to the other side!Delete this Joke

    test it out. does it work?Delete this Joke


    Add a Joke!


    Any help appreciated.
    Thanks
    Chet

  2. #2
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Change:
    WHERE ID=$jokeid';
    to:
    WHERE ID=' . $jokeid;

    When you post a block of code, be sure to put [ php] tags around it.
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

  3. #3
    SitePoint Member
    Join Date
    Jul 2003
    Location
    scranton
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you

  4. #4
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you understand why?

    If not would you like to make a guess?
    (hint: It has to do with single vs double quotes)
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

  5. #5
    SitePoint Member hollywood's Avatar
    Join Date
    Jul 2003
    Location
    Canada
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well I know I don't.

    I thought double quotes where used in echoing text. Also, there is a period in your solution as well. Doesn't that concantinate <sp?> the variable with existing text?
    "Well,... I picked a hellava day to quit Thorazine!"

  6. #6
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's correct about the concatenation!

    As for the quoting and single vs double quotes, check out this article from Zend: Using Strings :-)
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

  7. #7
    SitePoint Member hollywood's Avatar
    Join Date
    Jul 2003
    Location
    Canada
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Sam,

    One these days, I'll get the hang of this stuff.
    "Well,... I picked a hellava day to quit Thorazine!"

  8. #8
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's like a knowledgeable band-aid... pull it off as quickly as possible and you'll experience the least amount of pain. What I mean is that once you get over the hump with the basics, the rest comes pretty easily.

    "Looks like I picked the wrong day to stop sniffing glue."
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?


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
  •