开发者

declaring in PHP application forms w/ radio buttons & check boxes to save

开发者 https://www.devze.com 2023-03-15 06:51 出处:网络
I\'m really confused about how to start on my PHP with radio buttons and check boxes. How do I print out the option chosen by the user?

I'm really confused about how to start on my PHP with radio buttons and check boxes.

How do I print out the option chosen by the user? Also, declaring lots of fields with simila开发者_开发百科r name but with different answers.

It also needs to be connected to a mySQL database.


checkboxes:

<input type="checkbox" name="theoptions[]" value="1"> Option 1...
<input type="checkbox" name="theoptions[]" value="2"> Option 2...
<input type="checkbox" name="theoptions[]" value="3"> Option 3..

.

If user will submit checked 2 & 3 then $_REQUEST['theoptions'] will be array( 2, 3 )

To store in mysql you can create table for selected options for concrete user or implode() that array to store somethin like "2,3" or "2|3"


If you want to save an array in MYSQL I use serialize to save it in the mysql http://www.php.net/manual/en/function.serialize.php

and to get the array back then use http://php.net/manual/en/function.unserialize.php

so it would look like something like

$options=$_GET['theoptions']; //never use $_REQUEST
serialize($options);
//save to mysql database
0

精彩评论

暂无评论...
验证码 换一张
取 消