Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Forum Scripting

  1. #1
    Join Date
    Feb 2006
    Posts
    158
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Forum Scripting

    Hey DD,

    I'm writing my own little forum script, nothing special just a very basic forum to help me learn PHP and mySQL. I've learned the basics so far, but one concept is just confusing me a ton. Let's say my forums consists of one front page, and one Post a Message page. So on my post a message page, i put the form and all that, and i have my form action be "forum.php" (the name of my main forum page). So that when i post my message, the action sends the post information to the main forum page. Here's the problem: on the front forum page i can write the code so that data from the form is inserted into a MYSQL table and whatnot. My question is, if that chunk of code is left in the script of the main forum page, then every time that page loads, whether or not i clicked on the Submit button on my post a message page, won't it execute the script? and each time the page loads it'll add more rows to the table even if i didn't go through the whole post a message page thing?

    Sorry if that's worded strangely, but if anyone understands it and can help me i would greatly appreciate it.

    Thanks in advance.

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Then check if the data exists.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Feb 2006
    Posts
    158
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    How?

    $sql = "insert into Post_info
    (poster, message)
    values IF NOT EXISTS
    ('Johnny', "I've got a problem with PHP.")";

    then query that? that's just a guess.

    But if that's not it, how would i go about checking if the data already exists?

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    The same message is added each time or blank messages are entered when nothing was sent?

    If blank, you could use:

    if ($message = $_POST['message'])

    to see if it did indeed equal a value. Or perhaps

    if ($_POST['message'] != "")


    If you're getting repeats, then somehow you haven't cleared it from the script... I dunno... that's weird.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Feb 2006
    Posts
    158
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I don't quite understand.

  6. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I didn't get what you're saying...

    If you want to only do the posting action if there was data sent, then check by seeing if the post variable you would be using is empty or not, with those ifs.

    And if you're getting the data sticking with the browser through different pages (as it actually sounded like you were saying), then I have no clue... that's weird.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  7. #7
    Join Date
    Feb 2006
    Posts
    158
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I don't really know how to explain it that's the thing I guess.
    Is there any simple way to check for existing data within a table?
    Or is there some way to make it so that
    <form action="post.php" method="post"> sends the form data to post.php but sends the browser to forum.php ?

  8. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    You could have it sent to post.php, but that redirects to forum.php.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  9. #9
    Join Date
    Feb 2006
    Posts
    158
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I'll try to rephrase the question so you can understand better, because I really havn't a clue what to do.

    Let's say i'm reading this thread about my scripting problems. I see that you say i could use a redirect. Then i go click reply, type in my message in the reply box, and hit reply. When i press reply, i am taken back to this thread that i am replying to. Therefore i assume that on the thread page, there is some php code that inputs my reply into the database. My question is, if i log in to DD some time later, and come check this thread to see if you have posted, when this page loads, the PHP script will be run again. Thus inputting an exactly identical message into the database again, or a blank one. Because i sent no information from the reply page, yet the script is still on the thread page to be run each time the page is loaded.

    Make better sense?

  10. #10
    Join Date
    Feb 2006
    Posts
    158
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Ok I came up with a solution. Heh...the if statements were basically what i was looking for...just didn't see that earlier. Sorry. And thank you.

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
  •