I have 2 mysql tables companies and owner.
1 company can have multiple owners. So far I can insert the company and one owner just fine. But I am having a hard time inserting more owners on the same company. I don't fully understand how to get my value out of the for loop
Here is my code:
/* Owner Info */
$totalowners = 0;
$ownergender1 = $_POST["q60_Gender"];
$ownername1 = $_POST["q34_OwnerName"];
if(!empty($ownername1)){
$totalowners++;
}
$owneraddress1 = $_POST["q35_OwnerAddress"];
$ownercity1 = $_POST["q36_OwnerCity"];
$ownerstate1 = $_POST["q38_OwnerState"];
$ownerzip1 = $_POST["q48_OwnerZip"];
$sameaddress1 = $_POST["sameasbusiness"];
/* Owner 2 Info */
$ownergender2 = $_POST["q61_Gender"];
$ownername2 = $_POST["q39_OwnerName"];
if(!empty($ownername2)){
$totalowners++;
}
$owneraddress2 = $_POST["q43_OwnerAddress"];
$ownercity2 = $_POST["q42_OwnerCity"];
$ownerstate2 = $_POST["q49_OwnerState"];
$ownerzip2 = $_POST["q50_OwnerZip"];
/* Owner 3 Info */
$ownername3 = $_POST["q18_OwnerName"];
if(!empty($ownername3)){
$totalowners++;
}
$owneraddress3 = $_POST["q51_OwnerAddress"];
$ownercity3 = $_POST["q20_OwnerCity"];
$ownerstate3 = $_POST["q21_OwnerState"];
$ownerzip3 = $_POST["q27_OwnerZip"];
$ownergender3 = $_POST["q63_Gender"];
/* Owner 4 Info */
$ownername4 = $_POST["q54_OwnerName"];
if(!empty($ownername4)){
$totalowners++;
// echo "Last Owner right here" . $ownername4;
}
$owneraddress4 = $_POST["q57_OwnerAddress"];
$ownercity4 = $_POST["q58_OwnerCity"];
$ownerstate4 = $_POST["q56_OwnerState"];
$ownerzip4 = $_POST["q55_OwnerZip"];
$ownergender4 = $_POST["q60_Gender"];
require("inc/dbconnect.php");
if(!empty($fillingnumber)){
$sql = "INSERT INTO `Companies` (`fillingnumber` ,`businessname` ,`businessaddress` ,`datefiled`,`businesscity` ,`businessstate` ,`businesszip`) VALUES ('$fillingnumber','$businessname','$businessaddress','$edate','$businesscity', '$businessstate', '$businesszip')";
mysql_query($sql,$con);
for ( $i = 1; $i <= $totalowners;) {
if (!empty($sameaddress[$i])) {
$osql = "INSERT INTO `owner` (`ownerid`,`fillingnumber` ,`ownergender` ,`ownername`,`owneraddress`,`ownercity` ,`ownerstate` ,`ownerzip`) VALUES
('','$fillingnumber[$i]','$ownergender[$i]',$ownername.$i','$businessaddress.$i','$businesscity.$i', '$businessstate.$i', '$businesszip.$i')";
}else{
$osql = "INSERT INTO `owner` (`ownerid`,`fillingnumber` ,`ownergender` ,`ownername`,`owneraddress`,`ownercity` ,`ownerstate` ,`ownerzip`) VALUES ('','$fillingnumber.$i','$ownergender.$i','$ownername.$i','$owneraddress.$i','$ownercity.$i', '$ownerstate.$i', '$ownerzip.$i')";
}
mysql_query($osql,$con);
$i++;
}