Jump to content

Alternative to echo - or customization of it....


endouken

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.