Note that there are some explanatory texts on larger screens.

plurals
  1. POstore a php array in session from input form
    primarykey
    data
    text
    <p>I am having allot of trouble trying to get an array to work with sessions if anyone can help that would be great I'm not bothered about validation etc if I can just get it working i can then expand upon it.</p> <p>HTML</p> <pre><code>&lt;form method="post" action="array2.php"&gt; Select amount of tickets you require. &lt;select name="options[]"&gt; &lt;option value="1"&gt;1&lt;/option&gt; &lt;option value="2"&gt;2&lt;/option&gt; &lt;option value="3"&gt;3&lt;/option&gt; &lt;option value="4"&gt;4&lt;/option&gt; &lt;option value="5"&gt;5&lt;/option&gt; &lt;option value="6"&gt;6&lt;/option&gt; &lt;option value="7"&gt;7&lt;/option&gt; &lt;option value="8"&gt;8&lt;/option&gt; &lt;option value="9"&gt;9&lt;/option&gt; &lt;option value="10"&gt;10&lt;/option&gt; &lt;/select&gt; Select the acomidation you require. &lt;select name="options2[]"&gt; &lt;option value="camping"&gt;Camping&lt;/option&gt; &lt;option value="caravan"&gt;Caravan&lt;/option&gt; &lt;/select&gt; &lt;input type="submit" value="Go!" /&gt; &lt;/form&gt; </code></pre> <p>array2.php</p> <pre><code>&lt;?php session_start(); $checked = $_POST['options']; $checked2 = $_POST['options2']; $_SESSION['user'] = true; $_SESSION['checked'] = $checked; $_SESSION['checked2'] = $checked2; header('Location: array3.php'); ?&gt; </code></pre> <p>array3.php</p> <pre><code>&lt;?php session_start(); if(!isset($_SESSION['user'])){ die("To access this page, you need to &lt;a href='register.html'&gt;LOGIN&lt;/a&gt;"); } $checked = $_SESSION['checked']; $checked2 = $_SESSION['checked2']; ?&gt; &lt;?php for($i=0; $i &lt; count($checked &amp;&amp; $checked2); $i++){ echo "You have selected to receive " . $checked[$i] . " tickets&lt;br/&gt;"; echo "And you have selected to receive " . $checked2[$i] . " for accommodation are you sure? &lt;br/&gt;"; } ?&gt; </code></pre> <p>The main problem is that the values are not being passed from <code>array2</code> into <code>array3</code>, any help is welcomed.</p> <p>EDIT - this worked fine until I tried to add in the sessions to get it working over multiple pages so I'm sure thats where the problem is</p> <p>EDIT2 - thanks for all the help guys i got it working when I took out</p> <pre><code>$checked = $_POST['options']; $checked2 = $_POST['options2']; </code></pre> <p>From array 3 it worked :) much appreciated!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload