【发布时间】:2011-06-18 17:08:24
【问题描述】:
我想将此表单值插入数据库:
<input type="checkbox" name="brand1" id="brand1" value="1"> <label for="brand1">Brand 1</label>
<input type="checkbox" name="brand2" id="brand2" value="1"> <label for="brand2">Brand 2</label>
<input type="checkbox" name="brand3" id="brand3" value="1"> <label for="brand3">Brand 3</label>
<input type="checkbox" name="brand4" id="brand4" value="1"> <label for="brand4">Brand 4</label>
<input type="checkbox" name="brand5" id="brand5" value="1"> <label for="brand5">Brand 5</label>
这些文本框是通过 php 从数据库中的表中获取的,可能是变量
我想以这种格式插入数据库 如果品牌 1 被选中 $brand="1,";
最后像这样:
insert($name,$brands); and $brands = "1,2,3,4,5,";
如果用 if 和 while 写这个,但它不起作用,因为 if insert run in while {} 五次 insert Done 和 if insert run out of while {} , $brand = "5,"
感谢您对此问题的帮助或想法
意思是:
<form method="post" action="#">
<?php
$result = $db->getall(brands);
if(!empty($result)) {
while ( list($key,$val)=each($result) ) {
$brand_id = stripslashes($val["id"]);
$brand_name = stripslashes($val["name"]);
?>
<input type="checkbox" name="brand<?php print"$brand_id"; ?>" value="1" style="cursor:pointer;"><label for="brand<?php print"$brand_id"; ?>" style="cursor:pointer;"> <?php print"$brand_name"; ?></label>
<?php }} ?>
源输出:
<input type="checkbox" name="brand1" value="1"> <label for="brand1">Brand Name 1</label>
<input type="checkbox" name="brand2" value="1"> <label for="brand2">Brand Name 2</label>
<input type="checkbox" name="brand3" value="1"> <label for="brand3">Brand Name 3</label>
<input type="checkbox" name="brand4" value="1"> <label for="brand4">Brand Name 4</label>
<input type="checkbox" name="brand5" value="1"> <label for="brand5">Brand Name 5</label>
<input type="submit" value="Submit" />
</form>
提交表单时,插入源为:
<?php
$result = $db->getall(brands);
if(!empty($result)) {
while ( list($key,$val)=each($result) ) {
$brand_id = brand.stripslashes($val["id"]);
$brand_name = stripslashes($val["name"]);
$brand_ids = "brand.$brand_id";
if($$brand_ids==1) {$brands="$brandid,"}
}} ?>
$db->add_submenu("$brands");
【问题讨论】:
-
我认为您应该尝试编辑您的问题并再次解释所有内容,因为很难理解您要如何插入以及您的问题是什么。
-
$db->add_submenu("$brands");在 PHP 块之外。
标签: php database checkbox insert