basically i want to insert the name, date, time, info into a table. with the same click of the submit button i want to add the auto inc id value the first insert query creates, and place it into a separate table, along with the check box value.
with that...i want to create a new row in the second table for each of the check boxes that are selected
---------------------------------------------------
for example:
if this was inputed into the form:
name: this story
date: today
time: now
info: some info about the story
check box(out of 7 boxes): 1,3,6 were selected.
---------------------------------------------------
first table insert entry:
story_id(auto_inc) = '25'
story_name = 'this story'
story_time = 'today'
story_date = 'now'
story_info = 'some info about the story'
the first insert would add the new entry into the table on the db..
for the second..i wasnt sure if i had to do it separate or if i could do it at the same time...
1) i couldnt think of a way to retrieve the id from the first table and insert into the second without pulling it from the db. I would LIKE to do it all at once but i dont know if it is possible..
2) i dont know how to create multiple rows depending on how many check boxes have been checked
// Count the number of lines that was submitted $LineCount = count($_POST['ItemDescription']);
// Get the md5 of a blank line with the users ID and Order ID inserted to compare with later $BlankLineMD5 = md5("( NULL , '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '". $OrderID. "', '". $_SESSION['UserID'] . "', ''),"); $x = 0; while ($x < $LineCount) { // build the line with data that was posted if ($_POST['QTY'][$x] != ''){ if ($_POST['ANumber'][$x] == ''){ $ANResults = query("SELECT * FROM `anumber`", __LINE__, __FILE__); $ANrow = mysql_fetch_array($ANResults); $AANO = $ANrow['ACODE']; $NANO = NextAAnumber($ANrow['ACODE']); $ANUResults = query("UPDATE `anumber` SET `ACODE` = '".$NANO."' WHERE `NEXTUP` = 'A'", __LINE__, __FILE__); }else{ $AANO = $_POST['ANumber'][$x]; } $QueryLine = "(NULL, '". $_POST['ItemDescription'][$x]. "', '". $_POST['CustomerPartNumber'][$x] ."', '". $AANO ."', '". $_POST['QTY'][$x] ."', '". $_POST['Status'][$x] ."', '". $_POST['MinutesPerPart'][$x] ."', '". $_POST['OPSID'][$x] ."', '". $_POST['SubConSupplierID'][$x] ."', '". $_POST['PowderCoatCost'][$x] ."', '". $_POST['PaintColourID'][$x] ."', '". $_POST['Fabrication'][$x] ."', '". $_POST['OID'][$x] ."', '". $_POST['InvoiceDate'][$x] ."', '". $_POST['InvoiceBy'][$x] ."', '". $_POST['SellPrice'][$x] ."', '', '". $_POST['CostPrice'][$x] ."', '". $_POST['DueDate'][$x] ."', '". $_POST['DeliveryNoteNum'][$x] ."', '". $_POST['InvoiceNumber'][$x] ."', '". $_POST['DeliveredAmount'][$x] ."', '". $OrderID ."', '". $_SESSION['UserID'] ."', '". $_POST['Material'][$x] ."') ,";
// If the md5 of the line just created is the same as $BlankLineMD5
//if (md5($QueryLine) == $BlankLineMD5) { // Then exit the loop //break; } // Otherwise add the line to our query $BuildQuery .= $QueryLine; $x++; }
// Take the last character off the query because its a comma $BuildQuery = substr($BuildQuery, 0, -1);
// If $x is 0 then no lines must have been processed so dont run the query. if ($x != 0) { if (query($BuildQuery, __LINE__, __FILE__)) { $MessageColour = "Green"; $Message = "Order successfully added to the database"; } else { $MessageColour = "Red"; $Message = "An error occured when trying to insert your order."; } }
db('close');
}
__________________
There are 10 types of people on CodingForums,
Those who understand Binary and those who dont.
// If the form was submitted if (isset($_POST['story_name'])) { // Add new story to get the story_id db('open'); $results = query("INSERT INTO `dbname`.`table1` ( ,`story_name` ,`story_time` ,`story_date` ,`story_info`) VALUES ( , '$_POST[story_name]' , '$_POST[story_time]' , '$_POST[story_date]' , '$_POST[story_info]') ");
// Get the ID from inserted row above. $check_parent = mysql_insert_id();
// Start building the query $BuildQuery = "INSERT INTO `dbname`.`table2` ( , `check_parent` , `check_value`) VALUES ";
// Count the number of boxes that was submitted $LineCount = count($_POST['check_value']);
$x = 0; while ($x < $LineCount) { // build the line with data that was posted if ($_POST['check_value'][$x] != ''){
// Take the last character off the query because its a comma $BuildQuery = substr($BuildQuery, 0, -1);
// If $x is 0 then no lines must have been processed so dont run the query. if ($x != 0) { if (query($BuildQuery, __LINE__, __FILE__)) { $MessageColour = "Green"; $Message = "Order successfully added to the database"; } else { $MessageColour = "Red"; $Message = "An error occured when trying to insert your order."; } }
db('close');
} __________________
__________________
There are 10 types of people on CodingForums,
Those who understand Binary and those who dont.
Users who have thanked Arcticwarrio for this post: