kyleldi Posted April 16, 2008 Share Posted April 16, 2008 Hi All, So i'm attempting a script that basically echos "thank you for submitting" when a brief form is filled out. I've been running into trouble because the information is posted to a sql db, and i could not get the script right so I resorted to dreamweaver for one of their scripts. The only problem, is dreamweaver only allows the user to go to another page when the post is complete, where I'd like it to echo. Here's my code, is it possible anyone can tell me what i need to modify? I don't usually resort to scripts like this, but I need it to work and all... Thanks everyone! $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "referral")) { $insertSQL = sprintf("INSERT INTO referring_website (referalid) VALUES (%s)", GetSQLValueString($_POST['referral'], "int")); mysql_select_db($database_admin, $admin); $Result1 = mysql_query($insertSQL, $admin) or die(mysql_error()); $insertGoTo = "index.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } Form Code: <form id="referral" name="referral" method="POST" action="<?php echo $editFormAction; ?>"> <table width="76%" border="0"> <tr> <td width="43%"><div align="right">ThomasNet</div></td> <td width="57%"> <div align="center"> <input type="radio" name="referral" id="referral" value="2" /> </div></td> </tr> <tr> <td><div align="right">Google</div></td> <td><div align="center"> <input type="radio" name="referral" id="referral2" value="1" /> </div></td> </tr> <tr> <td><div align="right">Directly</div></td> <td><div align="center"> <input type="radio" name="referral" id="referral3" value="3" /> </div></td> </tr> </table> <br /> <input type="submit" name="submit" id="submit" value="Submit" /> <input type="hidden" name="MM_insert" value="referral" /> </form> Quote Link to comment Share on other sites More sharing options...
craygo Posted April 16, 2008 Share Posted April 16, 2008 One of the reason why they do that is so a person won't click refresh and keep inserting the same data over and over again. But if you want to echo out something without going to another page then change this $Result1 = mysql_query($insertSQL, $admin) or die(mysql_error()); $insertGoTo = "index.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } To this $Result1 = mysql_query($insertSQL, $admin) or die(mysql_error()); if(!$Result1){ echo "could not insert data"; } else { echo "Thank you for submitting your form"; } } What I would do is echo out those results then use a meta tag to redirect the page to another location. You would have to use a meta tag because one you output the results to the browser you can no longer use the header function of php. Ray Quote Link to comment Share on other sites More sharing options...
jonsjava Posted April 16, 2008 Share Posted April 16, 2008 <?php $editFormAction = $_SERVER['PHP_SELF']; if ($_GET['go'] == "post_data"){ if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "referral")) { $insertSQL = sprintf("INSERT INTO referring_website (referalid) VALUES (%s)", GetSQLValueString($_POST['referral'], "int")); mysql_select_db($database_admin, $admin); $Result1 = mysql_query($insertSQL, $admin) or die(mysql_error()); $insertGoTo = "index.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header("location:?go=complete"); } } if ($_GET['go'] == "complete"){ print "<center><strong><p>thank you for submitting</p></strong></center>"; } ?> <form id="referral" name="referral" method="POST" action="<?php echo $editFormAction; ?>?go=complete"> <table width="76%" border="0"> <tr> <td width="43%"><div align="right">ThomasNet</div></td> <td width="57%"> <div align="center"> <input type="radio" name="referral" id="referral" value="2" /> </div></td> </tr> <tr> <td><div align="right">Google</div></td> <td><div align="center"> <input type="radio" name="referral" id="referral2" value="1" /> </div></td> </tr> <tr> <td><div align="right">Directly</div></td> <td><div align="center"> <input type="radio" name="referral" id="referral3" value="3" /> </div></td> </tr> </table> <br /> <input type="submit" name="submit" id="submit" value="Submit" /> <input type="hidden" name="MM_insert" value="referral" /> </form> From what I can see, this should work fine. <I hope> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.