Note that there are some explanatory texts on larger screens.

plurals
  1. POvalidate options[] with isset
    text
    copied!<p>Hey i am having some trouble getting an options[] array to work, if anyone can help that will be great Form</p> <pre><code>&lt;form method="post" action="array2.php"&gt; &lt;select name="options[]"&gt; &lt;option value=""&gt;&lt;/option&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; &lt;input name="submit" type="submit" value="submit"&gt; &lt;/form&gt; </code></pre> <p>The array2.php</p> <pre><code>&lt;?php session_start(); if(isset($_POST['submit'])){ if($_POST['options[]'] == "" ){ header("Location: error.html"); exit; }else{ $checked = $_POST['options']; $_SESSION['checked'] = $checked; } } ?&gt; </code></pre> <p>Any help would be great, also what happens is even if it's an empty feild, the thing progress's to the rest of the script</p> <p>rest of script</p> <pre><code> &lt;?php for($i=0; $i &lt; count($checked); $i++){ echo "You have selected to recive " . $checked[$i] . " tickets&lt;br/&gt;"; } for($i=0; $i &lt; count($checked2); $i++){ echo "And you have selected to recive " . $checked2[$i] . " for accommodation are you sure? &lt;br/&gt;"; } ?&gt; </code></pre> <p>Sorry I am unable to reply to people for now soon as I posted it a class came to the empty room so need to wait an hour :/</p>
 

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