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.

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.

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 -->

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.