[Gloucs] problem with php

rob at cmsnet.org.uk rob at cmsnet.org.uk
Tue Apr 19 09:23:42 BST 2005


Hiya

Quoting stilman davis <stilman.davis at telinco.co.uk>:

<snip>

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

I think you need to change the form line to be:
<form action="test2.php" method="post">

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

Sounds reasonable.

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

Alternatively, you can pass the values around in hidden form input fields
(<input type="hidden" name="foo" value="bar">), or on the query string (<a
href="test.php?foo=bar">).

> Thank you for your help.
> Stilman Davis

Rob





More information about the gloucs mailing list