I am creating a hotel management website and I am trying to insert data into the following columns to a locally hosted phpmyadmin:
- gname
- phone
- ccn
- expmonth
- cvv
- checkin_date
- checkout_date
- cartCost
The php is stored in my htdocs>myproject>checkout.php.
I keep on getting the Fatal error:
Uncaught mysqli_sql_exception: Column ‘gname’ cannot be null in C:xampphtdocsmyprojectcheckout.php:24 Stack trace: #0 C:xampphtdocsmyprojectcheckout.php(24): mysqli_stmt->execute() #1 {main} thrown in C:xampphtdocsmyprojectcheckout.php on line 24:
<?php
$data = json_decode(file_get_contents('php://input'), true);
// Replace the database credentials with your own
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "thelivingroom";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Insert data into the database
$stmt = $conn->prepare("INSERT INTO guests (gname, email, phone, ccn, expmonth, cvv, checkin_date, checkout_date, cartCost) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->bind_param("sssssssss", $data["gname"], $data["email"], $data["phone"], $data["ccn"], $data["expmonth"], $data["cvv"], $data["checkin_date"], $data["checkout_date"], $data["cartCost"]);
if ($stmt->execute()) {
echo "Data inserted successfully";
} else {
echo "Error inserting data: " . $conn->error;
}
$stmt->close();
$conn->close();
?>
Here is the code that submits the data. Even when I hard-code data into the gname column, I am still getting this error. I tried changing the sendData function multiple times but the issue persists. Any thoughts on how I can get this data sent up?


