As it can be seen bellow I have written the php code bellow, but I don't know why is this not working if the session was not working then it should not have fetched data from database based on customer logged in, the session is working but when I click on pay button then the session don't work I don't know why is this not working. Please help me, help will is appreciated. It took me hours to find the error but still I couldn't. Thanks in advance
Notice: Undefined index: buy in C:\xampps\htdocs\FinalYearProject\checkout.php on line 45
<?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();
}
?>