为什么它会给我这个错误

时间:2017-02-02 23:50:48

标签: php session

正如我可以看到的那样,我已经编写了下面的PHP代码,但我不知道为什么如果会话不能正常工作则不起作用那么它不应该根据客户登录从数据库中获取数据,会话正在运行但是当我点击付费按钮然后会话不起作用我不知道为什么这不起作用。请帮助我,帮助将不胜感激。我花了几个小时才找到错误,但我仍然无法做到。提前谢谢你 注意:未定义的索引:在第45行购买C:\ xampps \ htdocs \ FinalYearProject \ checkout.php

<?php 
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "project";
$conn = new mysqli($servername, $username, $password, $dbname);

$pro_id = $_GET['buy'];
$select = "select * from products where Id='$pro_id'";
$run = mysqli_query($conn, $select);
$row = mysqli_Fetch_Array($run);
$product_id = $row['Id'];
$image = $row['Image'];
$title = $row['Title'];
$descript = $row['Descript'];
$price = $row['Price'];
$delivery = 5.99;
$finalpayment = $price+$delivery;

$customer_session_id = $_SESSION['customer_id'];

$select_customer = "select * from customer_register where Id='$customer_session_id'";
$connect_customer = mysqli_query($conn, $select_customer);
$run_customer = mysqli_fetch_array($connect_customer);
$customer_register_customer_id = $run_customer['Id'];
$customer_register_customer_first_name = $run_customer['first_name'];
$customer_register_customer_last_name = $run_customer['last_name'];
$fullname = $customer_register_customer_first_name + " " + $customer_register_customer_last_name;

if(isset($_GET['pay'])) {
    $first_name = $_POST['first_name'];
    $last_name = $_POST['last_name'];
    $address = $_POST['address'];
    $city = $_POST['city'];
    $post_code = $_POST['zip_code'];
    $phone_number = $_POST['phone_number'];
    $email_address = $_POST['email_address'];
    $card_numb = $_POST['car_number'];
    $card_code = $_POST['car_code'];
    $month = $_POST['month'];
    $year = $_POST['year'];
    $date = date('Y-m-d');
    $deliverydate = date('Y-m-d', strtotime("+3 days"));

    echo $sql = "INSERT INTO payment (Product_id, Product_name, Customer_id, Customer_name, Address, Post_code, City, Phone_numb, Email, Order_date)
            VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
        $sql;
    // making a new connection to the database using the variables declared for it at the top

    // Checking the connection
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    }

    // Prepare to write the sql query
    $stmt = $conn->prepare($sql);

    // Bindsthe variables to the parameters as strings.
    echo  $stmt->bind_param('isisssisss', $product_id, $title, $customer_session_id, $fullname, $address, $post_code, $city, $phone_number, $email_address, $date);

    // Execute the statement.
    $stmt->execute();

    echo $dsql = "INSERT INTO delivery (Product_id, Product_name, Customer_id, Customer_name, Delivery_date)
            VALUES (?, ?, ?, ?, ?)";
        $dsql;
    // making a new connection to the database using the variables declared for it at the top

    // Checking the connection
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    }

    // Prepare to write the sql query
    $dstmt = $conn->prepare($dsql);

    // Bind the variables to the parameters as strings.
    echo $dstmt->bind_param('isiss', $product_id, $title, $customer_session_id, $fullname, $deliverydate);

    // Execute the statement.
    $dstmt->execute();
}
?>

0 个答案:

没有答案