使用数组值遍历会话变量

btxsgosb  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(327)

有没有办法用数组值循环会话变量以插入到数据库中? $list_application 在这里我存储数组值
您将在我的代码中看到,我直接插入了$list\应用程序,它返回一个 Array 当我打印出来的时候。

if(isset($_POST['submit'])) {
    include('includes/dbconn.php');
    $list_application = $_SESSION['LIST_APPS'];
    $currUser= getenv("username");

    $get_data = "INSERT INTO technologyresults(examdate, technology, prof, eid) VALUES(CURDATE(),'$list_application', '$list_application','$currUser')";
    if($conn->query($get_data) === TRUE ) {
        include('includes/dbconn.php');
    } else {
        echo "Error: " . $get_data. "<br>" . $conn->error;
    }               
    $conn->close();
    header('location: summary.php');
}
kgsdhlau

kgsdhlau1#

如果我正确理解了您的问题,那么您需要的是将数组内爆为与插入匹配的字符串:

$list_application = implode("','", $_SESSION['LIST_APPS']) ;

在您的代码中,注意我对insert做了一些更改:

if(isset($_POST['submit'])) { include('includes/dbconn.php');

   $list_application = implode("','", $_SESSION['LIST_APPS']) ;

    $currUser= getenv("username"); $get_data = "INSERT INTO technologyresults(examdate, technology, prof, eid) VALUES(CURDATE(),'".$list_application. "','$currUser')"; if($conn->query($get_data) === TRUE ) { include('includes/dbconn.php'); } else { echo "Error: " . $get_data. "<br>" . $conn->error; } $conn->close(); header('location: summary.php'); }

相关问题