select items in array via checkbox form in php -


i tried create form array , make items selectable , able collect items individually processing variables blank screen when echo $_post['citem1']

<?php foreach($_session['cart'] $data1 => $data2) {echo '<input type = "checkbox" name = "citem1" value = "'.$data1.'"/> ' .    ' price:', $data2 . "<br>";}  ?> 

what want able select 1 or more of items , put them in separate variables. please.

var_dump of $_session=array (size=3) 'sugar' => string '989.32' (length=6) 'lolli' => string 'inquire' (length=7) 'caramel unreal' => string '00.00' (length=5) 

the name of field 'citem1', have value $_post['citem1'].

to send array have name 'citem1[]', , items receive php array:

<?php foreach($_session['cart'] $data1 => $data2) { echo '<input type = "checkbox" name = "citem1[]" value = "'.$data1.'"/> ' .    ' price:', $data2 . "<br>";}  ?> 

or, send key=>value this:

<?php foreach($_session['cart'] $data1 => $data2) { echo '<input type = "checkbox" name = "'.$data1.'" value = "'.$data2.'"/> ' .   ' price:', $data2 . "<br>"; }  ?> 

but in case need loop through $_post, better way is:

<?php foreach($_session['cart'] $data1 => $data2) { echo '<input type = "checkbox" name = "item['.$data1.']" value = "'.$data2.'"/> ' .   ' price:', $data2 . "<br>"; }  ?> 

with name="item[field]" can loop through $_post['item'] , key=>value.


Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -