Hi,
When you go to http://www.webdevelopershq.com/text2.php3 and add a comment on the next page where it says our joke was added if you reload that page it adds the joke into the database again and again for everytime you reload the page. Is there anyway to stop this?
Thanks,Code:<?php // If the user wants to add text if (isset($addjoke)): ?> <FORM ACTION="<?php echo($PHP_SELF); ?>" METHOD=POST> <P>Type your joke here:<BR> <TEXTAREA NAME="joketext" ROWS=10 COLS=40 WRAP></TEXTAREA> <BR><INPUT TYPE=SUBMIT NAME="submitjoke" VALUE="SUBMIT"></FORM> <?php else: //connection variables $dbconnect = mysql_connect("localhost", "user", "password"); //Cannot Connect if (!$dbconnect) { echo ("<p>Unable to connect to the database.</p>"); exit(); } //select database mysql_select_db("jokes", $dbconnect); //Cannot find DB if(! @mysql_select_db("jokes") ) { echo ("<p>Unable to locate the database at this time.</p>"); exit(); } echo("<font size='5'><b>Current Comments:</b></font><p>"); //get TheText from test $result = mysql_query("SELECT Joketext FROM Jokes"); //unable to get TheText if(!$result) { echo ("<p>Unable to process database query</p>"); exit(); } //show the text while ($row = mysql_fetch_array($result)) { echo("<table width='600' cellspacing='0' border='1' cellpadding='3' bordercolor='#666666' bgcolor='#DDDDDD'><tr><td width='600'>" . $row["Joketext"] . "</td></tr></table><p>"); } endif; ?> <?php // 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>"); } } ?> <P><font size="2" face="verdana"><A HREF="<?php echo($PHP_SELF); ?>?addjoke=1">Add Your Jokes!</A><br> <A HREF="<?php echo($PHP_SELF); ?>">View All The Jokes.</A></font></P>
Justin Sampson





Bookmarks