Hi,
I am trying to create a very simple website where road users report road problems. Website and Database (MySQL) has been created.
Firstly, customer arrives at the registration page. Fills form and submits. Data is inserted into db using insert.php. Then, page is directed to report page.
Secondly, customer fills in the form on second page to report problem. When submitted, there is an error. The error is that the Customer_ID (PK) generated in the register database is a FK in the 'Report' page and because the table Customer_ID(FK) does not get a value for Customer_ID (FK) from the insertreport.php, it does not allow the form to be inserted. Because these two tables are co-related, I'm stuck on how to design it better so that when the customer is registered, the problem that he/she reports is logged into the problem which indicates that it belongs to that customer.
Register form
<form action="insert.php" method="post">
Firstname:<br>
<input type="text" name="Firstname"><br>
Lastname:<br>
<input type="text" name="Lastname"><br>
Address:<br>
<input type="text" name="Address"><br>
Telephone:<br>
<input type="text" name="Telephone"><br>
E-mail:<br>
<input type="text" name="email"><br>
HRD Member:<br>
<input type="radio" name="HRD" value="Yes" checked> Yes<br>
<input type="radio" name="HRD" value="No"> No<br>
Subscribe Mailings:<br>
<input type="radio" name="SubscribeMailings" value="Yes" checked> Yes<br>
<input type="radio" name="SubscribeMailings" value="No"> No<br>
<input type="submit" value="Submit">
Register.php
$Firstname = $_POST['Firstname'];
$Lastname = $_POST['Lastname'];
$Address = $_POST['Address'];
$Telephone = $_POST['Telephone'];
$email = $_POST['email'];
$HRD= $_POST['HRD'];
$SubscribeMailings = $_POST['SubscribeMailings'];
include 'conn.php'; // using another php file to connect with database
$sql = "INSERT INTO `customer` (`Customer_ID`, `FirstName`, `LastName`, `Address`, `Telephone`, `Email`, `HRD`, `SubscribeMailings`) VALUES (NULL, '$Firstname', '$Lastname', '$Address', '$Telephone', '$email', '$HRD', '$SubscribeMailings')";
Report form
<form action="insertreport.php" method="post">
Location of problem (driver location sign, driver location sign, postcode etc):<br>
<input type="text" name="Location"><br>
Description (detailed) :<br>
<input type="text" name="Description"><br>
<input type="submit" value="Submit">
insertreport.php
$Location = $_POST['Location'];
$Description = $_POST['Description'];
include 'conn.php'; // using another php file to connect with database
$sql = "INSERT INTO `problem` (`Problem_ID`, `Location`, `Description`, `Job_start`, `Customer_ID`, `Staff_ID`, `Priority_ID`, `Status_ID`, Solution_ID`, `Job_end`) VALUES (NULL, '$Location', '$Description', CURRENT_TIMESTAMP, '', NULL, NULL, '', NULL, NULL)";