【问题标题】:store the checkbox value using set type [duplicate]使用设置类型存储复选框值[重复]
【发布时间】:2012-12-26 11:22:34
【问题描述】:

可能重复:
store multiple checkbox values to database using php and mysql

如何使用 php 和 mysql 使用设置的列类型将复选框值存储到单个字段。可能吗?

我的代码:

<?php
$genre = serialize($_POST['genre']);
$query = "INSERT INTO myset(genre) values('" . $genre . "')";
mysql_query($query) or die(mysql_error());
?>

它不工作。

【问题讨论】:

  • 我想将多个值存储在单个列字段中..

标签: php mysql set


【解决方案1】:

HTML

<input type="checkbox" name="genre[]" value="1">
<input type="checkbox" name="genre[]" value="2">..

PHP

<?php
$genre= @implode(',', $_POST['genre']);
$query = "INSERT INTO myset(genre) values('$genre')";
mysql_query($query) or die(mysql_error());
?>

在此之后,您将在(单个)流派列中找到值“1,2”。

【讨论】:

  • 是的..非常感谢..它工作得很好..
  • Yw.. 是的,我也喜欢 PHP 的“功能”。享受:P
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-25
  • 1970-01-01
相关资源
最近更新 更多