php - $_POST is not being set correctly -


front end code

    <form action="search.php" method="post">      <ul data-role="listview" data-filter="true" data-inset="true" data-filter-       reveal="true"  data-filter-placeholder="search ingredients">                      <!-- 1-10 -->                    <li>                         <input type="checkbox" name="search" id="ing1" class="custom" value="passion fruit"/>                         <label for="ing1">passion fruit</label>                     </li>                      <li>                         <input type="checkbox" name="search" id="ing2" class="custom" value="banana"/>                         <label for="ing2">banana</label>                     </li>                      <li>                         <input type="checkbox" name="search" id="ing3" class="custom" value="mango"/>                         <label for="ing3">mango</label>                     </li>                      <li>                         <input type="checkbox" name="search" id="ing4" class="custom" value="orange juice"/>                         <label for="ing4">orange juice</label>                     </li>                      <li>                         <input type="checkbox" name="search" id="ing5" class="custom" value="ice"/>                         <label for="ing5">ice</label>                     </li>                      <li>                         <input type="checkbox" name="search" id="ing6" class="custom" value="sausages"/>                         <label for="ing6">sausages</label>                     </li>                      <li>                         <input type="checkbox" name="search" id="ing7" class="custom" value="bacon"/>                         <label for="ing7">bacon</label>                     </li>                      <li>                         <input type="checkbox" name="search" id="ing8" class="custom" value="eggs"/>                         <label for="ing8">eggs</label>                     </li>                      <li>                         <input type="checkbox" name="search" id="ing9" class="custom" value="beans"/>                         <label for="ing9">beans</label>                     </li>                      <li>                         <input type="checkbox" name="search" id="ing10" class="custom" value="milk"/>                         <label for="ing10">milk</label>                     </li>              </ul>      <br />     <input type="submit" action="search.php" value="search recipes">     </form> 

php code

     if (isset($_post['search'])) {       $choices = $_post["search"];      $count = count($choices);       echo "<h1>" . $count . "</h1>";      echo "<h1>" . $choices . "</h1>";       } 

nothing being returned when check boxes suggests me checkbox not being picked correctly :s helpp!!!! making web app searchable list hence cod this

checkboxes not radiobuttons. names must different otherwise you're returning last one!

if want retrieve them all, have change every checkbox name search search[]. way, you'll able retrieve them single array, located $_request['search'] (*)

if, instead, want have 1 possible selection, change inputs type checkbox radiobutton , keep current name.

(*) $_request superglobal variable contains same values you'll find in $_post or $_get. it's best choice write flexible scripts (you may have change form's method , $_request won't have rewrite whole php script in end.


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -