SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Hybrid View

  1. #1
    JavaScript Guru (Big Ego) Arielladog's Avatar
    Join Date
    Jul 1999
    Location
    SC, USA
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've been readint he tutorial y'all have on this site...it's great.

    Anyway, to "learn" this stuff, I try tinkering with scripts, but it won't work for some reason. It displays the jokes, but for some reason, when I tell it to add a joke, it won't. Here's the code I've been trying to use. (Can someone also explain to me how 'if("ADD" == $submitjoke){' is supposed to work...I don't understand how that is triggered when the user clicks on the button and submits the form .... maybe I M just to used to JavaScript, but I want to UNDERSTAND the language, so please help. (since it displays the info fromt he database, I know that it is connecting.)

    <html>
    <head>
    <title>Today's Date</title>
    </head>
    <body>
    <?php

    $dbcnx = @mysql_connect("localhost","root","");

    mysql_select_db("jokes");

    ?>
    <h1>Add a Joke:</h1><br>
    <form method="post" action="<?php echo($PHP_SELF);?>">
    <textarea name="JokeText">Type your joke here:</textarea><br>
    <input type="submit" name="submitjoke" value="ADD">
    </form><br><Br>
    <?php

    if("ADD" == $submitjoke){
    $sql="INSERT INTO Jokes SET".
    "JokeText='JokeText', ".
    "JokeDate=CURDATE()";
    }

    mysql_query($sql)

    ?>
    <h1>Jokes thus far:</h1>
    <?php
    $jokes = mysql_query("SELECT JokeText FROM Jokes");

    while ($row=mysql_fetch_array($jokes)){
    echo("<P>" . $row["JokeText"]."</p>");
    }

    ?>
    </body>
    </html>

  2. #2
    SitePoint Zealot
    Join Date
    Nov 1999
    Location
    Manhattan!
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if("ADD" == $submitjoke) means "if the variable submitjoke is equal to ADD then..." in other words, this like checks if the user has pressed the submit button or if s/he has simply entered the url. I like to do it the following way (which I think makes more sense):

    echo "
    <from action='". $PHP_SELF ."' method='post'>
    <input type='hidden' name='submit' value='1'>
    ...
    ...
    ...
    </form>";

    if($submit) {

    // do stuiff

    }

    ----

    The variable named $submit will only contain the value 1 if the form has been submitted. In php, 1 = Boolean true, so the if statement will only execute if the form has been submitted.

    Hope this helps.

    Christian



  3. #3
    JavaScript Guru (Big Ego) Arielladog's Avatar
    Join Date
    Jul 1999
    Location
    SC, USA
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I see, now that makes more sense...thanx!

    ALso, anyone know how come the textarea isn't adding any stuff to the database, like it should?

  4. #4
    JavaScript Guru (Big Ego) Arielladog's Avatar
    Join Date
    Jul 1999
    Location
    SC, USA
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I dunno, but I was reading tutorial at sitepoint in conjuction with this one, and tried this code:

    if($submitjoke){
    $sql="INSERT INTO Jokes (JokeText,JokeDate) VALUES ('$JokeText',CURDATE())";
    }

    and it worked .. dunno why other one didn't

  5. #5
    SitePoint Zealot
    Join Date
    Nov 1999
    Location
    Manhattan!
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SQL used to UPDATE a record:

    UDPATE joke_db SET joke='Knock, Knock', author="Me" where joke_id='007'


    SQL used to INSERT a NEW record:

    INSERT INTO joke_db (joke_id, joke, author) VALUES ('', 'Knock, Knock', 'Me')

    Christian

  6. #6
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Sounds like Arielladog is using a version of MySQL prior to 3.22.10, which doesn't support the newer INSERT INTO table SET ... syntax.


    ------------------
    -Kevin Yank.
    http://www.SitePoint.com/
    Helping Small Business Grow Online!

  7. #7
    elm
    SitePoint Community Guest
    >Sounds like Arielladog is using a version
    >of MySQL prior to 3.22.10, which doesn't
    >support the newer INSERT INTO table
    >SET ... syntax.

    Yeah... that one kept me going circles for an hour. Thanks!

    I'm going to fire off an e-mail to my host and see if they are going to update the software.

    elm


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
  •