【问题标题】:how to Insert and echo checkboxes with Php mysql and mamp如何使用 Php mysql 和 mamp 插入和回显复选框
【发布时间】:2011-11-01 12:19:48
【问题描述】:

我真的很难让复选框起作用,我已经查阅了教程 并没有找到任何帮助...我不确定如何在 MAMP 中为复选框设置我的表格以及如何插入它...

如果有人可以提供帮助,那将是很棒的人......

HTML:

<form action="mainpage2.php" method="POST">
  Search : <input type="text" name="firstname" id="name" />
  <input type="submit" name="confirm" value="Submit" />
  <input type="checkbox" name="tick[]" value="male" />
  <input type="checkbox" name="tick[]" value="female" />
  <input type="checkbox" name="tick[]" value="alien" />
</form>   

PHP:

if(isset($_POST['confirm'])) {
    $subject = $_POST['firstname']; 
    $subjec = $_POST['tick']; 
    $result = mysql_query("INSERT INTO chipsticks (Name,sports) VALUES ('$subject'),('subjec');",$database);

【问题讨论】:

    标签: php mysql html mamp checkbox


    【解决方案1】:

    您需要展平数组才能将其存储在数据库中。

    if(isset($_POST['confirm']))
    {
        $subject = $_POST['firstname']; 
        $subjec = $_POST['tick']; 
    
        $sports = '';
        if(is_array($subjec) && count($subjec)>0)
        {
            $sports = implode(',',$subjec);
        }
    
        $result = mysql_query("INSERT INTO chipsticks (Name,sports) VALUES ('$subject','$sports')",$database);
    }
    

    你也可以使用serialize代替内爆

    【讨论】:

      猜你喜欢
      • 2019-09-18
      • 1970-01-01
      • 2014-05-22
      • 2012-06-17
      • 2015-08-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多