Log in

View Full Version : Forum Scripting



InNeedofHelp
06-07-2006, 08:14 PM
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.

Twey
06-07-2006, 08:59 PM
Then check if the data exists.

InNeedofHelp
06-07-2006, 09:02 PM
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.:p

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

djr33
06-07-2006, 09:41 PM
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.

InNeedofHelp
06-07-2006, 09:48 PM
I don't quite understand. :confused:

djr33
06-07-2006, 09:50 PM
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.

InNeedofHelp
06-07-2006, 10:38 PM
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 ?

djr33
06-08-2006, 12:02 AM
You could have it sent to post.php, but that redirects to forum.php.

InNeedofHelp
06-08-2006, 06:48 PM
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?

InNeedofHelp
06-08-2006, 09:35 PM
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. :D

Twey
06-09-2006, 06:39 AM
If blank, you could use:

if ($message = $_POST['message'])= is not ==. Don't confuse them.