I am trying to use on form to insert data into 3 different tables
<?php
if (isset($_POST["submit"])){
$servername = "localhost";
$username = "root";
$password = "";
$db = "test_db";
$conn = new mysqli($servername, $username, $password, $db);
if ($conn->connect_error){
die("Connection failed: ". $conn->connect_error);
}
$Vehicle_type = $_POST["Vehicle_type"];
$Vehicle_colour = $_POST["Vehicle_colour"];
$Vehicle_licence = $_POST["Vehicle_licence"];
$People_name = $_POST["People_name"];
$People_licence = $_POST["People_licence"];
$Incident_Date = $_POST["Incident_Date"];
$Incident_Report = $_POST["Incident_Report"];
$sql = "INSERT INTO Vehicle(Vehicle_type,Vehicle_colour,Vehicle_licence)VALUES
('$Vehicle_type','$Vehicle_colour','$Vehicle_licence')";
$query= mysqli_query($conn, $sql);
if($query){
$sql2 = "INSERT INTO People (People_name,People_licence)VALUES
('$People_name','$People_licence')";
$result= mysqli_query($conn, $sql2);
$sql3 = "INSERT INTO Incident (Incident_Report,Incident_Date)VALUES
('$Incident_Report','$Incident_Date')";
$result= mysqli_query($conn, $sql3);
echo "Your form was succesfully submitted✅";
} else {
echo "There was an error in submitting your form";
}
}
$conn->close() ;
?>
and this is my html
<form action="incident.php" method="post">
Report a new Incident⚠️
<br>
<br>
Incident report:<input type="text" name="Incident_Report"><br>
Incident Date:<input type="text" name="Incident_Date"><br>
Vehicle Model:<input type="text" name="Vehicle_type"><br>
Vehicle Colour:<input type="text" name="Vehicle_colour"><br>
Vehicle Licence number:<input type="text" name="Vehicle_licence"><br>
Owner: <input type="text" name="People_name"><br>
Driver licence number: <input type="text" name="People_licence"><br>
<input type="submit" name="submit" value="submit">
</form>
<br>