php - How to get user input to insert multiple records into database from table created with a for loop? -
i have created form requires user input information on fields , submit form. goal user input , insert new records on database. current challenges since used loop in php create table/form:
- i can not access input $_post
- not sure how go differentiating of rows , inputs each other (since used loop create them). thinking array...
please see screenshot of form working with.
below have submit button.
if (isset($_post['submit'])) { $date = date('m\/d\/y'); $ordnum = $_post['cpordernumber']; $ponum = $_post['cpponumber'] . $_post['cpponumberf']; $palnum = $_post['palnum']; $casecount = $_post['casecount']; $cpsflot = $_post['cpsflot']; $sscc = $_post['sscc']; if(!empty($_post['cpordernumber']) || !empty($_post['cpponumber'])) { require_once('mydatabase.php'); $query = "insert asn (date, ordnum, ponum, palnum, casecount, cpsflot, sscc ) values ('$date', '$ordnum', '$ponum', '$palnum', '$casecount', '$cpsflot', '$sscc')"; $insert = sqlsrv_query($dbc, $query); if( $insert === false ) { die('could not connect database'); } } else { die('please enter appropriate information'); } sqlsrv_close($dbc); }
and here having difficulty. can $date, $ordnum, , $ponum insert database $palnum not. can see i've commented out have tried use array.
<?php ($x = 1; $x < 25; $x++) { echo '<tr id="' .$x. '"> <td style="font-size: 160%" name="palnum" id="pallet">' .$x. '</td> <td id="casecount"><input type="number" name="casecount" id="inputtext_small" maxlength="2"/></td> <td id="hilltoplot"><input type="text" name="cpsflot" id="inputtext_order" value="" maxlength="10"/></td> <td id="sscc"><input type="number" name="sscc" id="inputtext_medd" value="" maxlength="4"/></td> </tr>'; $palnum[$x] = $x; //$palnum[$x] = 'palnum'.$x; //$palnum = $palnumx.$x; //$palnum1 = $palnum[1]; } //echo count($palnumx); //echo $palnum[1]; ?>
i think looking this. not 100% though. basically, can name input wityh brackets make behave array in post.
<input name="recurringname[]" value="moo" /> <input name="recurringname[]" value="moo2" />
if that, in post can access data way
$_post['recurringname'][0] == 'moo' $_post['recurringname'][1] == 'moo2'
i hope helps! let me know if did not understand clearly
Comments
Post a Comment