hello,
i have a email subscription form,on which we are entering email address and a group of categories of which the subscriber wants the coupon. categories are like Travel,gifts,electronics,food,health and beauty etc. . on form these categories are placed using check-box. user checks them and has to get only checked category related coupons.
我使用“枚举”数据类型来保存这些类别列表;使用枚举编辑器设置列表;将复选框值更改为受尊重的类别名称,但现在停留在插入查询上。 或者他们是否有任何其他有效的办法来做到这一点。
waiting.. thanx
<div class="InputOuterDiv"> <div class="EnquiryInpTitle"><strong>Enter Email Address:</strong></div> <div class="EnquiryInputBox"> <input name="" type="text" class="EnquiryInput" /> </div> </div> <div class="InputOuterDiv"> <div class="CategoryLabelTitle"><strong>Select Category:</strong></div> <div class="CategoryTitle"><input type="checkbox" value="Travel" /> Travel</div> <div class="CategoryTitle"><input type="checkbox" value="Shopping" /> Shopping</div> <div class="CategoryTitle"><input type="checkbox" value="Electronics" /> Electronics</div> <div class="CategoryTitle"><input type="checkbox" value="Entertainment" /> Entertainment</div> <div class="CategoryTitle"><input type="checkbox" value="Food" /> Food & Drink </div> <div class="CategoryTitle"><input type="checkbox" value="Gift" /> Gift flowers</div> <div class="CategoryTitle"><input type="checkbox" value="Health"/> Health & Beauty</div>
最佳答案
您需要为您的复选框提供一个名称,如下所示
<input type="checkbox" name="datatypes[]" value="travel" />
...等等。
这将在提交时为您提供一个数组,其中包含每个被点击的值。
您将无法为这些值使用 enum
字段,因为您无法控制选择哪些值组合。最好使用 varchar
字段并 join()
在将数组值插入表之前对其进行处理。
<?php
$dt = $_GET["datatypes"]; // this will be an array....
// check your array like this...
print "<pre>".print_r($dt,true)."</pre>";
// now insert it.
$query = "insert into my_table (datatypes) values ('".join(',',$dt)."')";
mysql_query($query);
?>
关于php - 插入枚举数据类型列的查询.. 从选定的复选框中获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25948814/