php - 插入枚举数据类型列的查询.. 从选定的复选框中获取值

标签 php mysql enums

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/

相关文章:

php - AMFPHP2.1与Flex的连接

java - 使用延迟获取类型检索外部对象的正确方法

Objective-C:我应该在哪里以及如何声明枚举?

php - 通过单个复选框传递多个变量

php - the_post_thumbnail_url() 导致缩略图支持处于事件状态的 fatal error

php - 当达到表中的时间时更新 mysql

c# - 创建枚举列表并将其传递给方法

php - 从另一个数据库中定义的sku查询产品图片

php - 使用 MySQL 进行土耳其语字符编码

swift - 如何访问在 Swift 中作为参数传递的二级嵌套枚举