POSTing data back to the same script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mjseaden
Forum Contributor
Posts: 458
Joined: Wed Mar 17, 2004 5:49 am

POSTing data back to the same script

Post by mjseaden »

Hello,

If I have a script script.php, which reads POST data at the beginning of the script and changes page according to the contents of the POST data, can a page with a FORM POST data back to the same script?

e.g.

Code: Select all

script.php:

if( $_POST['data'] == 'page' )
{
echo '
<form action="script.php" method="post">
<input type="hidden" name="page" value="data">
<input type="submit" name="submit" value="Submit To Same Script >>"/>
</form>';
}
else
{
 ?>
This is another bit of code.
<?php
}
I've tried the equivalent of this in CGI and I appear to be getting an HTTP 502 error (gateway).

Many thanks

Mark
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it's done quite often..
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

if(!empty($_POST['data']) && $_POST['data'] == 'page')
Using this you won't get undefined variable notices :wink:

Is is best to have you error reporting set to E_ALL, considering notices are bad practice and all

Code: Select all

error_reporting(E_ALL);
Post Reply