[Gloucs] problem with php

stilman davis stilman.davis at telinco.co.uk
Tue Apr 19 00:40:01 BST 2005


>
>
>You'll need to post a bit more code if you want help. Do you have a short
>example that shows your problem? It should be relatively easy to fix. You
>might want to look at http://uk.php.net/variables.external
>
>Keith
>  
>
Thank you for the link.

This code from that page works as expected ----

<?php
if (isset($_POST['action']) && $_POST['action'] == 'submitted') {
 echo '<pre>';
 print_r($_POST);
 echo '<a href="'. $_SERVER['PHP_SELF'] .'">Please try again</a>';
 echo '</pre>';
} else {
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
 Name:Â  <input type="text" name="personal[name]" /><br />
 Email: <input type="text" name="personal[email]" /><br />
 Beer: <br />
 <select multiple name="beer[]">
 <option value="warthog">Warthog</option>
 <option value="guinness">Guinness</option>
 <option value="stuttgarter">Stuttgarter Schwabenbräu</option>
 </select><br />
 <input type="hidden" name="action" value="submitted" />
 <input type="submit" name="submit" value="submit me!" />
</form>
<?php
}
?>

However if I cut it into two pages, test1.php

<?php
if (isset($_POST['action']) && $_POST['action'] == 'submitted') {
header("Location: test2.php");
exit();
} else {
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
 Name:Â  <input type="text" name="personal[name]" /><br />
 Email: <input type="text" name="personal[email]" /><br />
 Beer: <br />
 <select multiple name="beer[]">
 <option value="warthog">Warthog</option>
 <option value="guinness">Guinness</option>
 <option value="stuttgarter">Stuttgarter Schwabenbräu</option>
 </select><br />
 <input type="hidden" name="action" value="submitted" />
 <input type="submit" name="submit" value="submit me!" />
</form>
<?php
}
?>

and test2.php

<?php
 echo '<pre>';
 print_r($_POST);
 echo '<a href="'. $_SERVER['PHP_SELF'] .'">Please try again</a>';
 echo '</pre>';
?>

None of the posted values are seen in test2.php (I am assuming that 
print_r($_POST) will print out all the keys and values posted as it did 
in the first working example).

What I am trying to do is this --
check the data entered, pass the data to a database table, then go to 
the next page using some of the values entered.

The solution seems to be to use $_SESSION variables, but that is passing 
cookies which do not necessarily get destroyed if the sequence of pages 
is not adhered to. But perhaps that is an easy solution as well.

Thank you for your help.
Stilman Davis







More information about the gloucs mailing list