【发布时间】:2014-04-05 20:17:47
【问题描述】:
我正在处理一个电子商店项目,我在添加新产品时遇到了一些问题。 这涉及三个表:
- 产品:p_id、名称、价格
- 属性:a_id、名称(产品属性,例如颜色、品牌等)
- product_attribute:id、p_id、a_id、值、 (此处的值例如属性颜色为白色)
要添加新产品,我的 html 表单显示: 1. 名称和价格的文本字段 2. 一个复选框列表,显示所有属性以及用于输入其值的文本字段。
但我很困惑如何在数据库中插入这些信息。
代码如下:
$qry = "select att_name from attribute";
$res = mysql_query($qry);
while($row=mysql_fetch_array($res))
{
?>
<tr>
<td width="136" nowrap="nowrap" class="gridLabels1">
<input type="checkbox" name="chk_group[]" value='$row' /><?php echo $row['att_name'];?> <br /></td> // checkbox list of all attributes
<td width="740" class="gridValue1">
<input name="value" type="text" class="inputText" id="value" size="29"/> </td> // text fields to enter value
</tr>
<?php
}
?>
【问题讨论】:
-
向数据库插入数据的第一步是有一个 INSERT 语句。其次,您应该指定您使用的数据库。三、查这个问题,可能对stackoverflow.com/questions/5081360/…有帮助
标签: php html checkboxlist