将函数和会话插入数据库

时间:2016-11-16 07:06:44

标签: php html mysqli

我有一个插入但是idk如何将函数和会话插入我的数据库的查询。 谢谢你的帮助!!

<?php
if (isset($_POST['submit'])){

        $address   = $_POST['address'];
        $poscode   = $_POST['poscode'];
        $city      = $_POST['city'];
        $state     = $_POST['state'];
        $tel_no    = $_POST['tel_no'];
        $recipient = $_POST['recipient'];
        $date      = $_POST['date'];

        $image     = $_FILES['image']['name'];
        $image_tmp = $_FILES['image']['tmp_name'];

    move_uploaded_file($image_tmp,"receipt/$image");

        $insert_order = "insert into user_order(user_email,total_payment,address,poscode,city,state,tel_no,recipient,payment_status,image,date) values ('{$_SESSION['user_email']}','".total_price()."','$address','$poscode','$city','$state','$tel_no','$recipient','pending','$image','$date')";

        $insert_order =  mysqli_query($con, $insert_order);

if($insert_order){
    echo "<script>alert('Order has been placed!')</script>";
    echo "<script>window.open('user/my_account.php','_self')</script>";

}}
?>

1 个答案:

答案 0 :(得分:2)

请在php标记打开后添加此行。

session_start(); 

在没有启动会话的情况下,您无法在php中使用会话变量。

这适用于我的情况。请试试。