PHP code for insert checkbox value into spesific column on mysql with select form

前端 未结 1 1355
礼貌的吻别
礼貌的吻别 2020-12-22 09:36

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



        
相关标签:
1条回答
  • 2020-12-22 09:59

    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)');
        }
    }
    ?>
    
    0 讨论(0)
提交回复
热议问题