在表中的单个列中插入动态多个值

时间:2014-12-11 18:32:03

标签: php html mysql

我希望在一个列中插入多个条目.. 插入需要从文本字段中的表单中获取值。 帮我检索..

这是我的第1页代码..

$result = mysqli_query($con, "SELECT * FROM cse");
        while ($row = mysqli_fetch_array($result)) 
    {
        echo "<tr><td>" . $row["name"] . "</td>" . "<td>" . $row["bupin"] . "</td>";
        echo "<td>" . "<input type='text' name='1quiz1[".$row["bupin"]."]'>". "</td></tr>";
    }
    echo "</table>";

这是final11.php的代码

if (isset($_POST["1quiz1"])) 
{
    foreach ($presence as $key => $val) 
    {
        mysqli_query($con,"Insert into cse ");
    }
}
echo "Entered successfully..";

2 个答案:

答案 0 :(得分:0)

if (isset($_POST["1quiz1"])) {

    $keys = "";
    $values = "";
    foreach ($presence as $key => $val) {
        $keys .= $key+",";
        $values .= $val+",";
    }

    // remove last commas
    $keys = substr($keys, 0,-1);
    $values = substr($values, 0,-1);

    //insert
    mysqli_query($con,"Insert into cse (".$keys.") values (".$values.")");

    // you can here check the errors then if you need
}
echo "Entered successfully..";

答案 1 :(得分:0)

您不需要在输入名称属性括号中插入任何内容。换句话说,你必须做如下的事情:

echo "<td>" . "<input type='text' name='1quiz1[]'>". "</td></tr>";