Hi! I'm working on a little script, in which info sent through a form is written to a MySQL database. My problem is, after submitting the form, the visitor gets redirected to the page with the empty form again. There's no indication that his info was sent successfully. I would like to either * redirect the visitor to a success-page after successful submission or * display a message on the form page after successful submission (using php) And this without messing up the code for sending the form The problem is, I don't know where to start. Do I make changes to the <form> code, or do I edit the 'action' script file? Please help me out? Greetz! mieke
First example : <? /** * Example form letting the user know what's happening **/ if($_POST) { /** * This is where you code will be to check the form submission **/ if( strlen($_POST['item_1']) > 5 ) { $message = "Your name is less than five letters long<br />\n"; } else { $message = "Your name is longer than five letters long<br />\n"; } } ?> <!-- Next the tag to display the message generated by the action(s) above --> <?=$messages ?> <form action="" method="post"> Item 1 : <input type="text" name="item_1" /><br/> <input type="submit" value="Post" /> </form> Second example : <? /** * Example form redirecting the user after form submission **/ if($_POST) { /** * This is where you code will be to check the form submission **/ if( strlen($_POST['item_1']) > 5 ) { header("location:page_for_more_than_five_letters.php"); exit; } else { header("location:page_for_less_than_five_letters.php"); exit; } } ?> <form action="" method="post"> Item 1 : <input type="text" name="item_1" /><br/> <input type="submit" value="Post" /> </form> PHP:
use meta refresh or the header function http://en.wikipedia.org/wiki/Meta_refresh http://www.php.net/header
I have a simple code for you..try this out..if this is what you are looking for. <html> <body> <form id="form" name="form"> <table border="0" cellpadding="0" cellspacing="0" width="781"> <tr> <td align="Left" width="115" ><font face="Verdana" size="2"><strong>Name:</strong></font></td> <td align="Left" > <input name="Name" type="text" value="Enter Your Name" size="27" tabindex="1" /></td> </tr> <tr> <td width="115"><b><font face="Verdana" size="2">Item Name:</font></b></td> <td> <input name="ItemName" type="text" value="Enter Your Item Name" size="27" tabindex="1" /></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td><font face="Verdana"></font></td> <td> <input type="submit" name="Submit" value="Submit" style="float: left" /></td> </tr> </table> <? // Connect database. $host="localhost"; // MySQL Host name; commonly it is localhost. $db_user=""; // MySQL username. $db_password=""; // MySQL password. $database=""; // Database name. $db_table=""; //Table where you want to insert the information. mysql_connect($host,$db_user,$db_password); mysql_select_db($database); if (isset($_REQUEST['Submit'])) { mysql_query("INSERT INTO `userinfo` VALUES ('$name', '$itemname')"); echo "Thank you ".$Name.", You have item name as ".$ItemName; } ?> <p align="center"> </p> </form> </body> </html> PHP: Thanks,
Thanks for all the tips! I've found the solution to my problem. It was there all the time, I just didn't recognize it I just had to change the page name in header("Location: thanks.php") Greetz! Mieke Janssens