开发者

Storing Checkbox Array Data in individual variables

开发者 https://www.devze.com 2023-03-15 04:29 出处:网络
Another simple one from me: I have a form which features a checkbox section called: name = \"cat[]\" from which i am collecting answers with

Another simple one from me:

I have a form which features a checkbox section called:

name = "cat[]"

from which i am collecting answers with

$cat = $_POST ['cat'];

Now I can find out what or how many options were submitted and e开发者_运维技巧cho their values with

foreach ($cat as $item) echo "$item";

But what i want to do is store each returned value in an individual variable so i can add them individually to my table in MySql.

can anyone help me do this? Or am i going about things in a backwards way (probably)?

As always, any of your help is appreciated.

Thanks


foreach ($cat as $item) {

    $query = "INSERT into `table_name` (`col_name`) VALUES ('$item');";
    //do something with $query

}
0

精彩评论

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