tags:

views:

84

answers:

4

Hi all,

I Have a php form page where users fill the data and process page to add data to database, Its working fine, But problem is I need the results from process page to be displayed back on to my main page? How to get results back to main page?? ..

+1  A: 

In the form's action attribute, set the path to $_SERVER['PHP_SELF'] rather than processing file. This way, form will submit to same page where you can process it.

<form action="<?php echo $_SERVER['PHP_SELF'];?>">
.....
</form>
Sarfraz
Thanks Sarfraz, Actually I have two forms in 1 page , 1 forms does process some function on same page and other forms sends data to another page for processing and then it display data over there, I need to get that results back to my main page?
PHPNewuser
@Sarfraz I've always done this by setting action="". Is there a reason to prefer your method over mine?
Michael Clerx
@PHPNewuser: No you can use either method :)
Sarfraz
He Sarfranz, there is an XSS problem with $_SERVER['PHP_SELF'] (see: http://www.mc2design.com/blog/php_self-safe-alternatives ). Using action="#" should also work
edorian
A: 

How about

<form action="mainPage.php" ...>

Simple and your Data will be on the main page.

Tokk
There is no good idea. The good practice is to divide form file and script handler.
Alexander.Plutov
well it is on diferent files: form.php and mainPage.php
Tokk
Actually I have two forms in 1 page , 1 forms does process some function on same page and other forms sends data to another page for processing and then it display data over there, I need to get that results back to my main page
PHPNewuser
you could simply use a session or a database in this case. I think I missunderstood your question a little bit
Tokk
A: 

Use sessions. In script assign a error message to session variable and do redirect. On script.php

$_SESSION['error'] = 'Incorrect email';

index.php

echo $_SESSION['error'];

Don't forget session_start() in begin of scripts.

Alexander.Plutov
A: 

There's a wide variety of ways, depending on what you're talking about. You'll likely want to use session variables, though. In the processing script:

<?php
start_session();

// Do your processing here

$_SESSION['myvar'] = $finished_data;
?>

And in the main page that called it:

<?php
session_start();

if(!empty($_SESSION['myvar'])) {
     $data = $_SESSION['myvar'];
}

// Use $data here as you need
?>
Codeacula
Actually I have two forms in 1 page , 1 forms does process some function on same page and other forms sends data to another page for processing and then it display data over there, I need to get that results back to my main page
PHPNewuser
So use the $_SESSION as I gave. You can split those examples up. On the page for processing, use the first code block. On the main page, use the second to see if the data is set.
Codeacula