Re: array with session
| From: | Craig | Date: | Fri, 29 Nov 2002 13:33:37 +0000 |
| Subject: | Re: array with session | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-126470@lists.php.net to get a copy of this message | ||
You should have session_start(); on every page that you want to hold the
session.
The way I would do what you are trying to achieve is go the $_SUPERGLOBALS
way..
on the submit_information.php page:
<?php
session_start();
$_SESSION['image'] = $_POST['image'];
foreach($_SESSION['image'] as $foo){
echo $foo . "<br>\n";
}
?>
Also, another good way of debugging etc is to use the print_r() function
(http://www.php.net/print_r)
If you do :
<pre><?php print_r($_SESSION);?></pre>
This produces a nice formatted look at the the session arrays/structures -
same goes for all arrays.
Hope that helps,
Craig
"Laurence" <lt1115mu@yahoo.co.uk> wrote in message
news:20021129125851.33325.qmail@web14505.mail.yahoo.com...
>
> hello everyone,
>
> I'm trying to get some images value from a checkbox putting them in a
session to preserve the data. The array works perfectly without the
session_start() and session_register.
>
> can anyone help?
>
> html script
>
> <html>
> <head>
> <title></title>
> </head>
>
> <body>
> <form action="submit_information.php" method="post">
> <input type="checkbox" name=Image[] value="Image_One">
> <img src=".gif" name="Image_One"><br>
> <input type="checkbox" name=Image[] value="Image_Two">
> <img src=".gif" name="Image_Two"><br>
> <input type="checkbox" name=Image[] value="Image_Three">
> <img src=".gif" name="Image_Two"><br>
> <input type="checkbox" name=Image[] value="Image_four">
> <img src=".gif" name="Image_One"><br>
> <input type="checkbox" name=Image[] value="Image_five">
> <img src=".gif" name="Image_Two"><br>
> <input type="checkbox" name=Image[] value="Image_six">
> <img src=".gif" name="Image_Two"><br>
> <input type="submit" value="submit">
> </form>
> </body>
> </html>
>
> php script: submit_information.php
>
> <?php
> session_start();
> session_register("Image");
>
> $count = count($Image);
> for ($i=0; $i<$count; $i++)
> {
> echo $Image[$i];
> }
>
> //I also tried that
> /*foreach ($Image as $i=> $Img)
> {
> $Img == $Image[$i];
> echo $Img;
> }*/
>
> ?>
>
>
>
>
> ---------------------------------
> With Yahoo! Mail you can get a bigger mailbox -- choose a size that fits
your needs
>