如何将数组值从 $_post 存储到 db


How to store array values from $_post to db

我添加了一个表格列,该列添加了动态行,因此在提交时单击时,值应存储在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']}' ) ";

我正在获得 O/P 喜欢

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

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

提前致谢

阿米斯

<?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"].' ) ';
?>
相关文章: