|
Posted by theCancerus on 12/10/06 19:58
hi Nico
the example i provided to you works but for it to work you must "submit
your form, via input with
> type="submit" as pointed above....
also replace aktry.php in my example with name of the file in which the
code was saved
it will work with out fail.. in case it does not the canyou show me the
exact out put what it dispalys
On Dec 10, 5:18 pm, alo....@gmail.com wrote:
> Hi Nico.
>
>
>
>
>
> > <FORM METHOD="POST" ACTION="prova.php">
> > <b>Combination</b><br><br>
> > Element 1: <INPUT NAME="el1" TYPE="TEXT">
> > <BR>
> > Element 2: <INPUT NAME="el2" TYPE="TEXT">
> > <br>
> > <INPUT TYPE="SUBMIT" VALUE"Submit">
> > </FORM>
> > <br>
> > Combination<br><br>
>
> > <?php
> > session_start();
> > $_SESSION['combinations'][] = ($_REQUEST["el1"].$_REQUEST["el2"]);
> > print_r($_SESSION['combinations']);
> > ?>First, session_start() must be called before any output if you use
> Cookie based sessions (the majority of PHP implementations use this
> configuration). Seehttp://www.php.net/manual/en/function.session-start.phpfor more info.
>
> Then your script should be like this:
>
> ---file begin---
> <?php
>
> session_start();
>
> ?>
> <p>Do some output here. <?php echo "Other output here."; ?></p>
> <p>Etc.</p>
> <?php
>
> // Write something to the _SESSION array
> $_SESSION['something'] = "something that sould be saved in session";
>
> ?>
> ---file end---
>
> Doing that, your data contained in $_SESSION array will be saved
> between browser requests.
>
> > If I fill the two text fields, reload the page and then fill again the
> > two text fields, the new text overwrites the old one.If you just reload the page the browser will not send any data filled
> in forms. To do that you should submit your form, via input with
> type="submit" or type="image" or via document.formName.submit()
> javascript method.
>
> > I'd like that the array can include both the old and the new text.You're doing right in this statement:
>
> $_SESSION['combinations'][] = ($_REQUEST["el1"].$_REQUEST["el2"]);
>
> But it could be a bit better, you could save your form data in a more
> normalized way, like a form submit history, I guess you want to do
> something like that:
>
> $_SESSION['form_history'][] = $_REQUEST;
>
> So, to get the last form post, for example, you could do this way:
>
> $last_request = $_SESSION['form_history'][
> count($_SESSION['form_history']) - 1 ];
> print_r($last_request);
> echo "The last posted value of Element 1 was " .
> $last_request['el'];
>
> Note: the example statements was not tested.
>
> Hope I can help you!
[Back to original message]
|