php – Inserting into a table where you have a foreign key and want it to be inserted from another table-ThrowExceptions

Exception or error:

Hello I have this query where I want to insert some data and I have a foreign key I want it to be inserted from the other table because of its a primary key there

here’s my code:

$con = new mysqli("localhost", "root", "", "company");
$st = $con->prepare("INSERT INTO reservations(customer_id,players_number,res_date) VALUES(?,?,?)");
$st->bind_param("iii", $_POST["players_number"], $_POST["res_date"], $_GET["id"]);
$st->execute();
header('Location: http://localhost/tech/calendar.php');

the table I want to insert to is called reservations and the customer_id must come from the customer’s table where there it’s the primary key
and I have a form under this code which leads to the same page to get to the code above

enter image description here

Thanks in advance!

when I go to the calendar of the customer I have this url

enter image description here

when I press the add reservation button it has the id in the url using $_GET method

enter image description here

This is the error I get:

enter image description here

I’m sorry if it’s not a very clear question but I’m new to this and doing my Internship with lots of tasks where i got to the point of desperate!!

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *