无法在$ _POST [$ var]中输入

时间:2017-10-09 17:17:59

标签: php

我搜索了类似但没有发现的主题, 我尝试使用我的表名来创建复选框表单,这样人们就可以检查表单中的内容,并在数据库的good列中插入那些复选框的值。

现在复选框显示

        $sql = "SELECT `COLUMN_NAME` FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE `TABLE_SCHEMA`='#the name of my database#' AND `TABLE_NAME`='#the name of the table#'";
        $result = mysqli_query($conn,$sql);
        $i = '1';

        while($row =  mysqli_fetch_assoc($result))
        {
            $long_nom_colomne = print_r($row, true); // get my column name
            $long_nom_colomne_fin = substr($long_nom_colomne, 28); // cut the beginning of the string: Array ( [COLUMN_NAME] => 
            $nom_colomne = substr($long_nom_colomne_fin, 0, -2); // cut the end
            ${'tache' . $i} = $nom_colomne; // i got the name of the column in a variable $var name
            $i++; 
        }
        $debut = '12'; // start at $tache12 because i don't want to show 1 to 11 column name
        $i = $debut;

        $tache = mysqli_query($conn,$sql);
            while($row =  mysqli_fetch_assoc($tache))
            {
                if(isset(${'tache' . $i}))
                {
        ?>
    <label>
    <input type="checkbox" name="<?php echo ${'tache' . $i}; ?>" value="<?php echo ${'tache' . $i}; ?>">&nbsp;
    <span class="wpcf7-list-item-label"><?php echo ${'tache' . $i}; ?></span>
    </label> 
//each check box get their name from the column name = (i.e. cat, dog, fish, ...), get their value (i.e. cat, dog,....) and appear as a label. THIS WORK
        <?php
                }
            $i++;
            }

在我将数据放入数据库的处理页面中,我有

$sql = "SELECT `COLUMN_NAME` FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE `TABLE_SCHEMA`='#name of my database#' AND `TABLE_NAME`='#name of the table#'";
$result = mysqli_query($conn,$sql);
$i = '1';
while($row =  mysqli_fetch_assoc($result))
{
    $truc = isset($_POST[${'tache' . $i}]) ? $_POST[${'tache' . $i}] : 'don t work'; 
    echo $truc; 
    $i++;
}
$debut = '12'; // will be send in a post so i only have one place to change it if i want
$i = $debut;
$set_value = mysqli_query($conn,$sql);
while($row2 =  mysqli_fetch_assoc($set_value))
{
    if(isset(${'tache' . $i}))
    { 
        $t = ${'tache' . $i};
        echo $t; // to test if its not ${'tache' . $i}; who don't work in the request
        ${'sql_' . $s} = "INSERT INTO tache ($t) VALUES 
        ('".mysqli_real_escape_string($conn,$t)."')";
    }
$i++;
}
$i = $debut;

我收到了错误:

Parse error: syntax error, unexpected '$' in #my_file# on line 148
Notice: Undefined variable

这是我以前从未尝试过的事情,但每次在我的数据库中添加列时都需要更改所有代码

0 个答案:

没有答案