webmaster1 Posted March 30, 2009 Share Posted March 30, 2009 Hi! I have a basic contact form which validates itself and writes to a database when submitted. I want to display a message (Thank you. Message has been sent.) which would replace the form. I've tried using: exit(); but this replaces the entire page. Does anyone know where I'm going wrong? (I can post more code if required) Quote Link to comment https://forums.phpfreaks.com/topic/151675-using-exit-after-processing-a-form/ Share on other sites More sharing options...
Maq Posted March 30, 2009 Share Posted March 30, 2009 What exactly are you trying to do? You may want to post some relevant code. Quote Link to comment https://forums.phpfreaks.com/topic/151675-using-exit-after-processing-a-form/#findComment-796499 Share on other sites More sharing options...
webmaster1 Posted March 30, 2009 Author Share Posted March 30, 2009 <?php if (isset($_POST['submit'])) { //VALIDATION if (strlen($_POST['yourname']) > 0) {$yourname=TRUE;} else {$yourname=FALSE; $message_yourname="<span style='font-family:Arial, Helvetica, sans-serif;font-size:12px;color:#FF0000;font-weight:bold;'> *You forgot to enter your name!</span>";} if (strlen($_POST['youremail']) > 0) {$youremail=TRUE;} else {$youremail=FALSE; $message_youremail="<span style='font-family:Arial, Helvetica, sans-serif;font-size:12px;color:#FF0000;font-weight:bold;'> *You forgot to enter your email!</span>";} if (strlen($_POST['subject']) > 0) {$subject=TRUE;} else {$subject=FALSE; $message_subject="<span style='font-family:Arial, Helvetica, sans-serif;font-size:12px;color:#FF0000;font-weight:bold;'> *You forgot to enter a subject!</span>";} if (isset($_POST['yourmessage'])) { $yourmessage = trim($_POST['yourmessage']); if ($yourmessage == "" || empty($yourmessage)) { $message_yourmessage = "<span style='font-family:Arial, Helvetica, sans-serif;font-size:12px;color:#FF0000;font-weight:bold;'> *You forgot to enter a message!</span>"; } } if ( $yourname && $youremail && $subject && $yourmessage ) { //DEFINE VARIABLES FOR SQL include("db_info.php"); mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to establish a connection to the relevant database."); $ipaddress = getenv('REMOTE_ADDR'); $yourname = mysql_real_escape_string($_POST['yourname']); $youremail = mysql_real_escape_string($_POST['youremail']); $recipients = mysql_real_escape_string($_POST['recipients']); $subject = mysql_real_escape_string($_POST['subject']); $yourmessage = mysql_real_escape_string($_POST['yourmessage']); $query = "INSERT INTO contactform VALUES ('',NOW(),'$ipaddress','$yourname','$youremail','$recipients','$subject','$yourmessage')"; mysql_query($query); echo "Thank you for contacting us!"; exit(); //END THE IF VARIABLE = TRUE CONDITION } } ?> The above code shows how the form validates itself and then writes to a database. With each succesful submit I want a message to be shown in place of the form. The above code actually replaces the entire page. Quote Link to comment https://forums.phpfreaks.com/topic/151675-using-exit-after-processing-a-form/#findComment-796503 Share on other sites More sharing options...
webmaster1 Posted March 30, 2009 Author Share Posted March 30, 2009 Any takers? Quote Link to comment https://forums.phpfreaks.com/topic/151675-using-exit-after-processing-a-form/#findComment-796513 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.