I have a query that is displaying potential items to add to a final invoice. The query returns multiple rows and I need to be able to allow the user to click a "complete" button and finalize this invoice. A couple of things that need to happen:
1) the user should have to click a checkbox next to each record and only those records that are checked would be included
2) each records should be stored in a new table (e.g. CompleteInvoice)
What I have below is only inserting 1 record (and there should be 12 in this particular case) and when I do an echo var_dump($_POST) there is also just the one record's info being displayed. I need to insert all the records, any ideas (the checkbox issue can come after, I think I need to figure out the multiple insert problem first).
The INSERT ...
1) the user should have to click a checkbox next to each record and only those records that are checked would be included
2) each records should be stored in a new table (e.g. CompleteInvoice)
What I have below is only inserting 1 record (and there should be 12 in this particular case) and when I do an echo var_dump($_POST) there is also just the one record's info being displayed. I need to insert all the records, any ideas (the checkbox issue can come after, I think I need to figure out the multiple insert problem first).
Code:
<form method="post"> while ... { ... <input type="hidden" name="CompleteValue[CompleteTimeId]" value="<?php echo $Row['TimeId'];?>" /> <input type="hidden" name="CompleteValue[CompleteTimeUser]" value="<?php echo $Row['TimeUser'];?>" /> ... } // end while </form>
Code:
if (isset($_POST['Insert'])) { $random = substr(number_format(time() * rand(),0,'',''),0,6); $sql = ""; foreach($_POST['CompleteValue'] as $key => $val){ if($val != ""){ $sql .= "'$val',"; } } $sql = substr($sql,0,-1); $insertSQL = "INSERT INTO `TimeCompleteInvoice` (InvoiceID,CompleteTimeId,CompleteTimeUser) VALUES ('$random',$sql)"; mysql_query($insertSQL); header("Location: mysite.com..."); }
Comment