$php_mysql$ Posted August 20, 2011 Share Posted August 20, 2011 how can i disply this message withing the form echo "data submitted successfully!"; currently after validation check when data is entered the message show on top of my page not within the form function insertDATA($postData) { if(!ifEmailExists($postData['email'])){ $sql = " INSERT INTO tbl SET email = '".$postData['email']."', name = '".$postData['name']."', phone = '".$postData['phone']."' "; echo "data submitted successfully!";//this line withing the form executeSql($sql); } Quote Link to comment https://forums.phpfreaks.com/topic/245273-display-a-success-message-after-form-is-submitted/ Share on other sites More sharing options...
titan21 Posted August 20, 2011 Share Posted August 20, 2011 Have a look at redirecting the user if teh data submitted is correct. Header("Some Location") should be able to do this for you. Have a look at http://uk.php.net/manual/en/function.header.php. Quote Link to comment https://forums.phpfreaks.com/topic/245273-display-a-success-message-after-form-is-submitted/#findComment-1259733 Share on other sites More sharing options...
$php_mysql$ Posted August 20, 2011 Author Share Posted August 20, 2011 i can get it done by redirecting but i want to get the message within the same page without success page, is it possible? Quote Link to comment https://forums.phpfreaks.com/topic/245273-display-a-success-message-after-form-is-submitted/#findComment-1259737 Share on other sites More sharing options...
titan21 Posted August 20, 2011 Share Posted August 20, 2011 You'll probably be looking at a solution with AJAX which would be preferable. Or perhaps you can submit back to this page and do the checks for validity there. My advice would be to look at AJAX tho. Quote Link to comment https://forums.phpfreaks.com/topic/245273-display-a-success-message-after-form-is-submitted/#findComment-1259741 Share on other sites More sharing options...
Pikachu2000 Posted August 20, 2011 Share Posted August 20, 2011 Just store the message in a variable and echo it wherever you want to echo it. Quote Link to comment https://forums.phpfreaks.com/topic/245273-display-a-success-message-after-form-is-submitted/#findComment-1259744 Share on other sites More sharing options...
Username: Posted August 20, 2011 Share Posted August 20, 2011 function insertDATA($postData) { if(!ifEmailExists($postData['email'])){ $sql = " INSERT INTO tbl SET email = '".$postData['email']."', name = '".$postData['name']."', phone = '".$postData['phone']."' "; echo "data submitted successfully!";//this line withing the form $res = executeSql($sql); if($res) { echo "<img src='path/to/image.jpg'></img."; } else { die(mysql_error()); } } I don't know if that will work, since you never told us how executeSql works, and you'll have to have the link for the image in the img tag. Quote Link to comment https://forums.phpfreaks.com/topic/245273-display-a-success-message-after-form-is-submitted/#findComment-1259762 Share on other sites More sharing options...
$php_mysql$ Posted August 20, 2011 Author Share Posted August 20, 2011 the executeSql is for database connection, how can i store the message in variable and display it in other page? Quote Link to comment https://forums.phpfreaks.com/topic/245273-display-a-success-message-after-form-is-submitted/#findComment-1259773 Share on other sites More sharing options...
$php_mysql$ Posted August 20, 2011 Author Share Posted August 20, 2011 i know it would be something like $message = ""; $message = "submitted successfully"; but how am i to fetch it? Quote Link to comment https://forums.phpfreaks.com/topic/245273-display-a-success-message-after-form-is-submitted/#findComment-1259778 Share on other sites More sharing options...
titan21 Posted August 20, 2011 Share Posted August 20, 2011 Can you not test your variables and decided what you want to output (if anything) Use echo() to output any html. Quote Link to comment https://forums.phpfreaks.com/topic/245273-display-a-success-message-after-form-is-submitted/#findComment-1259780 Share on other sites More sharing options...
$php_mysql$ Posted August 20, 2011 Author Share Posted August 20, 2011 did that but in my form gape nothing is displaying stored in variable but if i put message like echo "submitted"; that does show the message in the form page but in head section Quote Link to comment https://forums.phpfreaks.com/topic/245273-display-a-success-message-after-form-is-submitted/#findComment-1259782 Share on other sites More sharing options...
titan21 Posted August 20, 2011 Share Posted August 20, 2011 Can you post your code so we can have a look at it? Quote Link to comment https://forums.phpfreaks.com/topic/245273-display-a-success-message-after-form-is-submitted/#findComment-1259802 Share on other sites More sharing options...
darkfreaks Posted August 20, 2011 Share Posted August 20, 2011 how can i put html inside a variable? //make sure there are NO space in your html or you wil lget a unexpected T_SL error $example= <<<EOF <html><body></body></html> EOF; echo $example; you will need to do IF or ELSE statements to determine what gets outputted where. Quote Link to comment https://forums.phpfreaks.com/topic/245273-display-a-success-message-after-form-is-submitted/#findComment-1259882 Share on other sites More sharing options...
OneShot Posted August 20, 2011 Share Posted August 20, 2011 Not 100% sure if I am understanding what exactly you want but if I am this would work...... function insertDATA($postData) { if(!ifEmailExists($postData['email'])){ $sql = " INSERT INTO tbl SET email = '".$postData['email']."', name = '".$postData['name']."', phone = '".$postData['phone']."' "; return header(sprintf("Location: %s", 'yourpage.php?success=yes')); //echo "data submitted successfully!";//this line withing the form executeSql($sql); } When the query is sucessful the use will be redirected back to the original page with the message. // yourpage.php if(!empty($_GET['success'])){ if($_GET['success'] == 'yes'){ $Success = 'data submitted successfully'; } } //Then place this where ever you want the message to appear. if(isset($Success)){ echo $Success; } Quote Link to comment https://forums.phpfreaks.com/topic/245273-display-a-success-message-after-form-is-submitted/#findComment-1259896 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.