SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Member BZN Erik's Avatar
    Join Date
    Dec 2000
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello. I've posted messages before when I wanted to learn PHP and I didn't even know how to start and end commands, well, I'm back!
    On this page: http://www.webmasterbase.com/article.php/228/479
    it says the whole code to a page for the Jokes Table in MySQL. I already did the table in MySQL so no worrys on that, and acouple pages before that page link above, it has two other pages. One that does a list of the Jokes, the other submiting them. I can't get the submitting one or the combination page (the link above) to work! I already filled in my databases host, username, and pass. I can't figure it out!
    First page with a list of jokes (no jokes yet, because I need the second page so I can insert jokes!): http://below-zero.com/pics/test.php
    The page with the combination of the two, the source is the first link above: http://below-zero.com/pics/test2.php

    Hopfully someone can answer this, even Kevin himself
    Erik S.
    CEO and Editor in Chief of Below Zero Network

  2. #2
    SitePoint Member BZN Erik's Avatar
    Join Date
    Dec 2000
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anyone? Pleeease? Maybe I did do something wrong in the MySQL... but that first page showed up right...

    Did anyone else do this and see if it worked?
    Erik S.
    CEO and Editor in Chief of Below Zero Network

  3. #3
    Not Bad, eh? Justin Sampson's Avatar
    Join Date
    Aug 2000
    Location
    N.S., Canada
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could you post your PHP code into a post? Be careful not to post your mySQL password.

    I can't tell what happening without seeing the code

  4. #4
    SitePoint Member BZN Erik's Avatar
    Join Date
    Dec 2000
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, its the same as http://www.webmasterbase.com/article.php/228/430
    But here it is anyways, hehe...


    <HTML>...<BODY><?php // If the user wants to add a joke if (isset($addjoke)):?>
    <FORM ACTION="<?php echo($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"></FORM><?php else:
    // Connect to the database server $dbcnx = @mysql_connect( "localhost", "root", "password"); 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") ) { echo( "<P>Unable to locate the joke " . "database at this time.</P>" ); exit(); }
    // If a joke has been submitted, // add it to the database. if ("SUBMIT" == $submitjoke) { $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($deletejoke)) { $sql = "DELETE FROM Jokes " . "WHERE ID=$deletejoke"; 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) { echo("<P>Error performing query: " . mysql_error() . "</P>"); exit(); } // 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='$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='$PHP_SELF?addjoke=1'>" . "Add a Joke!</A></P>"); endif; ?></BODY></HTML>
    Erik S.
    CEO and Editor in Chief of Below Zero Network

  5. #5
    SitePoint Member BZN Erik's Avatar
    Join Date
    Dec 2000
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It must be something in MySQL, because I'm sure if Kevin did that, it should be right

    But I put in everything that it said to do in the article/tutorial! Crazy stuff... Maybe if someone could make another real quick one with the MySQL Table info and a form so I can post into it like "submit.php" or something?
    Erik S.
    CEO and Editor in Chief of Below Zero Network

  6. #6
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you go back and edit your post and wrap your formatted PHP code in php tags so that we can see the code properly with the line breaks? On the page with the form where you can edit your post click on the "vB code" link under "Quick Help" to see what I mean.

  7. #7
    SitePoint Member BZN Erik's Avatar
    Join Date
    Dec 2000
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As I said before, its the same code thats on http://www.webmasterbase.com/article.php/228/479 !!!
    Please go there to see it. It must be right though... but i double double double cheaked my MySQL Table and it looks good too! Bah, my host hasn't been on for two days straight and hes awesome at this, so thats why I'm here!
    Erik S.
    CEO and Editor in Chief of Below Zero Network

  8. #8
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I did this tutorial in January. With PHP 4 I had a problem with my code. Here is my correspondence with Kevin:

    Me:
    Hi Kevin,

    Yesterday I downloaded Apache, PHP and MySQL for Win32 and immediately got stuck into your tutorials at sitepoint.

    Anyway, I'm up to your "challenge" where you ask us to modify your code to allow the user to delete jokes from the jokes database.

    Just wanted to let you know that I ran your code and get the following error

    Warning Undefined variable: submitjoke in c:\phpweb/joke2.php on line 30


    I fixed the bug by modifying the following code

    from:

    if ("SUBMIT" == $submitjoke)

    to:

    if (isset($submitjoke) && "SUBMIT" == $submitjoke)


    Just thought I'd let you know. Thanks for the great tutorials!
    Kevin's reply
    This appears to be the result of more stringent checking in PHP4 than in
    PHP3 (which was used to develop the example in question). The problem should
    also be fixable by simply inverting the order of the terms in the comparison
    for equality:

    from:

    if ("SUBMIT" == $submitjoke)

    to:

    if ($submitjoke == "SUBMIT") {

    Thanks again!
    That might be the problem. However, you are getting a parse error at http://below-zero.com/pics/test2.php so I suspect that you have a more elementary syntax error in your code.

  9. #9
    SitePoint Member BZN Erik's Avatar
    Join Date
    Dec 2000
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm new to PHP, so I wouldn't know what that really means? A MySQL problem? If so, have any ideas so fix it or what the problem might be? PS: I'm gonna try and replace that, maybe it'll work, I'll repost if so.
    Erik S.
    CEO and Editor in Chief of Below Zero Network

  10. #10
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Regarding parse errors.

    A compiler/interpreter will "parse" the code before it compiles it. When a compiler "parses" the code it checks it for syntax errors. At the end of the day, programming code is just a "design" whereby we tell the compiler/interpreter what we want our program to do - and the compiler/interpreter goes off and produces the machine code to do it.

    So, if by parsing your code the compiler/interpreter finds a syntax error (a missing ";" or "}" or ")" or a mis-spelt "if/while/else" etc - then it doesn't bother trying to compile the code - it returns a parse error. This tells you to check your syntax for errors before bothering the compiler again. Unfortunately compilers have no intuition nor any sense of humour.
    Last edited by freakysid; Mar 18, 2001 at 23:43.

  11. #11
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how true... I hate errors! The horrible, hidious, white screen with black, default text covering two lines! Don't worry... if you haven't learned to hate that screen, you will!

    It makes me write cleaner, neater, better code though.. I cut down on errors!

    curse errors!
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services

  12. #12
    SitePoint Addict
    Join Date
    Nov 2000
    Location
    London, UK
    Posts
    223
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One other thing (although I'm sure you already know this):
    When you copy paste the code on webmasterBase (all of it actually, not just the tutorial), all of the " signs some to be some very deformed version, and just copy pasting it all won't work. The easiest way is to do a search-and-replace to fix them, but you need to do 2 because the opening and end quotes seem to be different symbols.
    I dunno, but this seems a bit odd to me ... anyone on SP want to comment on why it is this way?

    ... what's the world coming to?


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
  •