endouken Posted March 27, 2011 Share Posted March 27, 2011 Hi all, Example scenario: I have a page (let's call it pageone.php) which contains a form. On submit the form calls a php script (let's call it script.php) which includes an echo statement if a "IF query" is false. Problem is, the echo appears at the url www.mysite.com/script.php - how do i display the echo (or an alternative to it) back on /pageone.php - and is it possible to customize where on the page this message is displayed? (i.e. after the relevant part of the form the message relates to). I've done a little reading into print and echo statements, but if someone could link me or give me some pseudo code for the form and then the script so i can see how script prints / echos / 'whatever's' to the form i'd really appreciate it. Cheers all, Tom. Link to comment https://forums.phpfreaks.com/topic/231869-alternative-to-echo-or-customization-of-it/ Share on other sites More sharing options...
chris.smith Posted March 27, 2011 Share Posted March 27, 2011 Hi all, Example scenario: I have a page (let's call it pageone.php) which contains a form. On submit the form calls a php script (let's call it script.php) which includes an echo statement if a "IF query" is false. Problem is, the echo appears at the url www.mysite.com/script.php - how do i display the echo (or an alternative to it) back on /pageone.php - and is it possible to customize where on the page this message is displayed? (i.e. after the relevant part of the form the message relates to). I've done a little reading into print and echo statements, but if someone could link me or give me some pseudo code for the form and then the script so i can see how script prints / echos / 'whatever's' to the form i'd really appreciate it. Cheers all, Tom. It would be much easier to integrate the form into pageone.php and if needed use require or require_once to include script.php. You could identify an input by a $_GET key, as in: http://local/pageone.php?form=submit Cheers. Link to comment https://forums.phpfreaks.com/topic/231869-alternative-to-echo-or-customization-of-it/#findComment-1192912 Share on other sites More sharing options...
.josh Posted March 27, 2011 Share Posted March 27, 2011 script.php <?php // start a session session_start(); // do query stuff if (query is false) { // create a session variable $_SESSION['errorMsg'] = 'error message here'; // kick user back to previous page (the page that requested this script) header('Location: ' . $_SERVER['HTTP_REFERER']); exit(); } pageone.php <?php // start session session_start(); // if variable exists, echo it out if ($_SESSION['errorMsg']) echo $_SESSION['errorMsg']; ?> <!-- form stuff here --> Link to comment https://forums.phpfreaks.com/topic/231869-alternative-to-echo-or-customization-of-it/#findComment-1192915 Share on other sites More sharing options...
endouken Posted March 27, 2011 Author Share Posted March 27, 2011 script.php <?php // start a session session_start(); // do query stuff if (query is false) { // create a session variable $_SESSION['errorMsg'] = 'error message here'; // kick user back to previous page (the page that requested this script) header('Location: ' . $_SERVER['HTTP_REFERER']); exit(); } pageone.php <?php // start session session_start(); // if variable exists, echo it out if ($_SESSION['errorMsg']) echo $_SESSION['errorMsg']; ?> <!-- form stuff here --> Perfect - i was having trouble figuring out the correct structure so this is exactly what i needed to understand. :-) Thanks! Tom. Link to comment https://forums.phpfreaks.com/topic/231869-alternative-to-echo-or-customization-of-it/#findComment-1192918 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.