使用选择表单将复选框值插入到 mysql 上的特定列的 PHP 代码

PHP code for insert checkbox value into spesific column on mysql with select form(使用选择表单将复选框值插入到 mysql 上的特定列的 PHP 代码)
本文介绍了使用选择表单将复选框值插入到 mysql 上的特定列的 PHP 代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我需要帮助 php 代码来识别我的复选框值插入到一些特定的列中,我的表单是这样的.

I need help php code to identify my checkbox value insert in to some spesific coloumn, my form like this.

<input type="checkbox" name="A" Value="Animal">Animal <br/>
<input type="checkbox" name="B" Value="Ball">Ball <br/>
<input type="checkbox" name="C" Value="Champ">Champ <br/>

<label for="select">Category</label>
<select name="select" size="1">
<option value="Category 1">Category 1</option>
<option value="Category 2">Category 2</option>
<option value="Category 3">Category 3</option>
</select>
<br/>
<input type="submit" name="Submit" value="Submit">

我需要如果选择类别 1 并提交复选框值将插入到表列cat1"中,我选择类别 2 并提交复选框值将插入到表列cat2"中.table = id, cat1, cat2, cat3

i need if select category 1 and make submit the checkbox value will insert in to table column "cat1" and i select category 2 and make submit the checkbox value will insert in to table column "cat2". table = id, cat1, cat2, cat3

推荐答案

创建这个 php 代码

Create this php code

<?php
mysql_connect('localhost', 'username', 'password');
mysql_select_db('myTable');
$val = array();
if (isset($_POST['A']))
    $val[] = $_POST['A'];
if (isset($_POST['B']))
    $val[] = $_POST['B'];
if (isset($_POST['C']))
    $val[] = $_POST['C'];
$value = implode(', ', $val);
if (isset($_POST['select'])) {
    $col = $_POST['select'];
    if ($col == 'Category 1') {
        $query = mysql_query('INSERT INTO myTable(cat1) VALUES($value)');
    }
    else if ($col == 'Category 2') {
        $query = mysql_query('INSERT INTO myTable(cat2) VALUES($value)');
    }
    else if ($col == 'Category 3') {
        $query = mysql_query('INSERT INTO myTable(cat3) VALUES($value)');
    }
}
?>

这篇关于使用选择表单将复选框值插入到 mysql 上的特定列的 PHP 代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Subtract time in PHP(在 PHP 中减去时间)
Limit execution time of an function or command PHP(限制函数或命令 PHP 的执行时间)
How to sum N number of time (HH:MM Format)?(如何求和 N 次(HH:MM 格式)?)
How to get current time in milliseconds in PHP?(如何在 PHP 中以毫秒为单位获取当前时间?)
How to check if time is between two times in PHP(如何检查时间是否在 PHP 中的两次之间)
Convert number of minutes into hours amp; minutes using PHP(将分钟数转换为小时数分钟使用 PHP)