Page 1 of 1

POSTing data back to the same script

Posted: Thu Mar 16, 2006 9:00 am
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

Posted: Thu Mar 16, 2006 9:02 am
by feyd
it's done quite often..

Posted: Thu Mar 16, 2006 10:06 am
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);