samedi 12 août 2017

showing individual values out of foreach with values from checkbox

Am a newbie,i have a checkbox,that passes values to a foreach loop which then gives me a result of selected items as a list working fine.However i would like to obtain to obtain all the individuals separately probably each under a new variable so that i can reuse all the checked values separately.Please help

THE FORM.

<form action="" method="post"
       <a target="_blank" href="paris.jpg"><img src="flour.jpg" alt="Paris" style="width:150px"></a><input type="checkbox" name="day[]" value="50 kg flour-50ksh"/><input type="checkbox" name="shipping[]" value="$50.00"><label>50 kg flour-50ksh</label>
       <a target="_blank" href="paris.jpg"><img src="milk.jpg" alt="Paris" style="width:150px"></a><input type="checkbox" name="day[]" value="50 kg milk-50ksh"/><input type="checkbox" name="shipping[]" value="$10.00 "><label>50 kg milk-10ksh</label>
       <a target="_blank" href="paris.jpg"><img src="maize.jpg" alt="Paris" style="width:150px"></a><input type="checkbox" name="day[]" value="50 kg maize-50ksh"/><input type="checkbox" name="shipping[]" value="$20.00 "><label>50 kg maize-20ksh</label>
       <a target="_blank" href="paris.jpg"><img src="oil.jpg" alt="Paris" style="width:150px"></a><input type="checkbox" name="day[]" value="50 kg oil-50ksh"/><input type="checkbox" name="shipping[]" value="$30.00 "><label>50 kg oil-30ksh</label>
       <a target="_blank" href="paris.jpg"><img src="rice.jpg" alt="Paris" style="width:150px"></a><input type="checkbox" name="day[]" value="50 kg rice-50ksh"/><input type="checkbox" name="shipping[]" value="$40.00 "><label>50 kg rice-40ksh</label><br/>
       <a target="_blank" href="paris.jpg"><img src="soap.jpg" alt="Paris" style="width:150px"></a><input type="checkbox" name="day[]" value="50 kg soap-50ksh"/><input type="checkbox" name="shipping[]" value="$50.00"><label>50 kg soap-50ksh</label>
       <a target="_blank" href="paris.jpg"><img src="juice.jpg" alt="Paris" style="width:150px"></a><input type="checkbox" name="day[]" value="50 kg juice-50ksh"/><input type="checkbox" name="shipping[]" value="$50.00"><label>50 kg juice-50ksh</label><br>
       <label for="name"> Mobile:</label>
       <input type="number"  placeholder="10" id="mobile" name="mobile"  maxlength="10" size="10" pattern="[0-10]{10}" required/>
       <label for="name">Names:</label>
       <input type="text" id="name" name="name" required formtarget="_blank"/>  
       <label for="location">location details:</label>
       <input type="text" id="location" name="location" required/>
       <input type="hidden" name="submitted" value="true"/><br>
   <input type="submit" name="submit" value="Submit"/><br>

Form has double checkboxes ,ignore the other.

PHP CODE

<?php
if(isset($_POST['submit'])){
foreach($_POST['day'] as $day)
{
echo $day;
}
}
?>

WHAT I GET 50 kg milk-50ksh50 kg maize-50ksh50 kg oil-50ksh50 kg rice-50ksh50 kg juice-50ksh

how can i make it be like a==50 kg milk-ksh50 b=.... c=...so that i can assign maybe $john=a? then i will be able to reuse $john?

Please help out.




Aucun commentaire:

Enregistrer un commentaire