hahaitwork Posted October 31, 2012 Share Posted October 31, 2012 Like the title says: Submit Form - Error/Success message on Index file At the "insertken.php" I got this script: This is the end by the way.. Anyhow, I would like to have this Error or Successful message on my index file ( form.php ) Any idea how I can make that happen ? The thing is that I would really like my website not to go to the other page, but rather update on the same site, like.. ajax etc. But it also needs to remove everything in the form, and show a success/error message at the buttom. Maybe this wasn't a good way to explain but, yeah? ask if you wounder about anything. Could send a picture if needed. $sql="INSERT INTO $tbl_name(id, name, description, price, sla, quantity, fix)VALUES('$id', '$name', '$description', '$price', '$sla', '$quantity', '$fix')"; $result=mysql_query($sql); if($result){ echo "Successful"; echo "<BR>"; echo "<a href='form.php'>Back to main page</a>"; } else { echo "ERROR"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/270109-submit-form-errorsuccess-message-on-index-file/ Share on other sites More sharing options...
cyberRobot Posted October 31, 2012 Share Posted October 31, 2012 To execute PHP code, a request needs to be sent to the server. The same page can be called, but it needs to be reloaded. Quote Link to comment https://forums.phpfreaks.com/topic/270109-submit-form-errorsuccess-message-on-index-file/#findComment-1389005 Share on other sites More sharing options...
Christian F. Posted October 31, 2012 Share Posted October 31, 2012 (edited) Since I recently posted this in another thread, to give an example of a solution to pretty much the same issue: My contact form processing code. The $Template->_FORM_FIELD_{name} properties are being used by the template engine to pre-populate the form with already posted data, and $Template->_MESSAGE to add a message above the form. The template engine also uses the $Page variable to display the actual form, and since it's never overwritten in the script it'll always show the form after the code has been parsed. However, if you don't want the page to reload (even with pre-populating the fields), then you will need to use AJAX. Edited October 31, 2012 by Christian F. Quote Link to comment https://forums.phpfreaks.com/topic/270109-submit-form-errorsuccess-message-on-index-file/#findComment-1389019 Share on other sites More sharing options...
hahaitwork Posted October 31, 2012 Author Share Posted October 31, 2012 Since I recently posted this in another thread, to give an example of a solution to pretty much the same issue: My contact form processing code. The $Template->_FORM_FIELD_{name} properties are being used by the template engine to pre-populate the form with already posted data, and $Template->_MESSAGE to add a message above the form. The template engine also uses the $Page variable to display the actual form, and since it's never overwritten in the script it'll always show the form after the code has been parsed. However, if you don't want the page to reload (even with pre-populating the fields), then you will need to use AJAX. Thanks, will take a look when I got the time Quote Link to comment https://forums.phpfreaks.com/topic/270109-submit-form-errorsuccess-message-on-index-file/#findComment-1389053 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.