0

我添加了一个表格列,它添加了动态行,所以当点击提交时,值应该存储在 db 中,带有 php 代码

if (isset($_POST['submit'])) 
{
foreach($_POST AS $key=>$value)
{
$sql = "INSERT INTO `shows` ( `from` ,  `to` ,  `seats` ,  `cost` ,  `screen`  ) VALUES(  '{$_POST['first_name']}' ,  '{$_POST['last_name']}' ,  '{$_POST['tamil']}' ,  '{$_POST['english']}' ,  '{$_POST['computer']}' ) ";

我越来越喜欢

INSERT INTO `shows` ( `from` , `to` , `seats` , `cost` , `screen` ) VALUES( 'Array' , 'Array' , 'Array' , 'Array' , 'Array' )

所以只有数组变量存储在我的数据库中 如何在我的数据库中存储值

提前致谢

阿米斯

4

1 回答 1

1
<?php 
if (isset($_POST['submit'])) {
    foreach($_POST as $varname => $value) {
        $clean = trim($value);
        $clean = striptags($clean);
        $clean = mysql_real_escape_string($clean); // use inplace of addslashes
        //create sanitized array
        $cleanVars[$varname] = $clean;
    } 

}
$sql = 'INSERT INTO `shows` ( from ,  to,  seats ,  cost ,  screen  ) VALUES('. $cleanVars["first_name"].','. $cleanVars["last_name"].','. $cleanVars["english"].','. $cleanVars["tamil"].','. $cleanVars["computer"].' ) ';
?>
于 2013-09-06T11:20:37.273 回答