Whats up!!
I am trying to add Multiple Lines to Multiple Tables.
The problem I am running accross is insuring that the auto_increment Primary Key from one table(quote_detail) stays the same as the Foreign Key in another table(quoete_header).
I used the LAST_INSERT_ID function and this worked fine for adding one record to the db via an HTML/PHP form, but I can't figure out how to add multiple records.
Please see the code below and let me know how I can assure that the two auto_increment #'s are the same in each table.
Here ia the form I use to add the data to the db:
<?
if(!$submitForm) {
echo "<form action=\"VaddbTEST.php\" method=\"post\">"
."<table border=\"1\" cellspacing=\"4\" cellpadding=\"4\" width=\"30%\">"
."<tr>"
."<td class=\"sidepad\"><b>Avnet Materials Service - Request for Quote<BR>All fields are required</b>"
."</table><br>"
."<table border=\"1\" cellspacing=\"0\" cellpadding=\"0\">"
."<tr>"
."<th align=\"center\" class=\"sidepad\">Mfg"
."<th align=\"center\" class=\"sidepad\">Part Number"
."<th align=\"center\" class=\"sidepad\">Customer"
."<tr>"
."<td><input type=\"text\" name=\"Mfg\" size=\"3\">"
."<td><input type=\"text\" name=\"Part_Number\" size=\"30\">"
."<td><input type=\"text\" name=\"customer\" size=\"25\">";
for($i=1;$i<7;$i++) {
echo "<tr>"
."<td><input type=\"text\" name=\"Mfg".$i."\" size=\"3\">"
."<td><input type=\"text\" name=\"Part_Number".$i."\" size=\"30\">"
."<td><input type=\"text\" name=\"customer".$i."\" size=\"25\">";
}
echo "</table>"
."<tr>"
."<td align=\"left\">"
."<br>"
."<table border=\"1\" cellspacing=\"0\" cellpadding=\"0\">"
."<tr>"
."<th align=\"right\" class=\"sidepad\"><b>Comments</b>"
."<td><textarea cols=\"50\" name=\"Comments\" rows=\"4\"></textarea>"
."</table>"
."</table>"
."<br>"
."<input type=\"submit\" name=\"submitForm\" value=\"Submit RFQ\">"
."</form>";
?>
And here is what I came up with thus far to add this data to each table:
<?
if(isset($_POST['submitForm'])) {
$POST[Mfg] = strtoupper($POST[Mfg]);
$POST[Part_Number] = strtoupper($POST[Part_Number]);
$POST[customer] = strtoupper($POST[customer]);
$host="localhost";
$user="billy";
$pass="murray";
$dbName="vad";
$connect=mysql_connect($host,$user,$pass) OR die ("Unable to connect");
$db=mysql_select_db($dbName,$connect) OR die ("Unable to select database");
$sql="INSERT INTO quote_detail
VALUES ('' , '".$POST[Mfg]."' , '".$POST[Part_Number]."')";
if(mysql_query($sql)) {
echo "<center><table border=\"1\" cellspacing=\"4\" cellpadding=\"4\" width=\"30%\">"
."<tr>"
."<td class=\"sidepad\" align=\"center\"><b>Insert Into Quote_Detail Complete<br></b>";
}
else{
echo "<center><table border=\"1\" cellspacing=\"4\" cellpadding=\"4\" width=\"30%\">"
."<tr>"
."<td class=\"sidepad\" align=\"center\"><b>Cannot Insert Into Quote_Detail</b>";
}
}
for($i=1;$i<7; $i++) {
if($_POST['Mfg'.$i] AND ($_POST['Part_Number'.$i])) {
$sql1="INSERT INTO quote_detail
VALUES ('' , '".$_POST['Mfg'.$i]."' , '".$_POST['Part_Number'.$i]."')";
$result=mysql_query($sql1);
}
$sql2="INSERT INTO quote_header
VALUES('' , LAST_INSERT_ID() , '".$_POST[customer]."')";
if(mysql_query($sql2)) {
echo "<tr>"
."<td class=\"sidepad\" align=\"center\"><b>Insert Into Quote_Header Complete<br></b></center>";
}
else{
echo "<tr>"
."<td class=\"sidepad\" align=\"center\"><b>Cannot Insert Into Quote_Header</b>"
."</table>";
}
}
?>
Please help!!
Bill😕