我有一个包含这些列的表(数据库)
like this http://netelity.com/table.JPG
我有一个静态表单,用户可通过该表单定义分期付款。静态24输入框就像这样
<form name="installment" method="post" action="" enctype="multipart/form-data" onsubmit="return validate()">
<table id="dt_hScroll" class="table table-striped">
<thead>
<tr>
<th>SL No.</th>
<th>Amount</th>
<th>Due Date</th>
</tr>
<tr>
<td> 1. </td>
<td>
<input type="text" name="installment1" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date1" class="tcal span4" value="<?php //echo date("Y-m-d"); ?>" />
</td>
</tr>
<tr>
<td> 2. </td>
<td>
<input type="text" name="installment2" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date2" class="tcal span4" />
</td>
</tr>
<tr>
<td> 3. </td>
<td>
<input type="text" name="installment3" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date3" class="tcal span4" />
</td>
</tr>
<tr>
<td> 4. </td>
<td>
<input type="text" name="installment4" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date4" class="tcal span4" />
</td>
</tr>
<tr>
<td> 5. </td>
<td>
<input type="text" name="installment5" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date5" class="tcal span4" />
</td>
</tr>
<tr>
<td> 6. </td>
<td>
<input type="text" name="installment6" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date6" class="tcal span4" />
</td>
</tr>
<tr>
<td> 7. </td>
<td>
<input type="text" name="installment7" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date7" class="tcal span4" />
</td>
</tr>
<tr>
<td> 8. </td>
<td>
<input type="text" name="installment8" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date8" class="tcal span4" />
</td>
</tr>
<tr>
<td> 9. </td>
<td>
<input type="text" name="installment9" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date9" class="tcal span4" />
</td>
</tr>
<tr>
<td> 10. </td>
<td>
<input type="text" name="installment10" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date10" class="tcal span4" />
</td>
</tr>
<tr>
<td> 11. </td>
<td>
<input type="text" name="installment11" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date11" class="tcal span4" />
</td>
</tr>
<tr>
<td> 12. </td>
<td>
<input type="text" name="installment12" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date12" class="tcal span4" />
</td>
</tr>
<tr>
<td> 13. </td>
<td>
<input type="text" name="installment13" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date13" class="tcal span4" />
</td>
</tr>
<tr>
<td> 14. </td>
<td>
<input type="text" name="installment14" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date14" class="tcal span4" />
</td>
</tr>
<tr>
<td> 15. </td>
<td>
<input type="text" name="installment15" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date15" class="tcal span4" />
</td>
</tr>
<tr>
<td> 16. </td>
<td>
<input type="text" name="installment16" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date16" class="tcal span4" />
</td>
</tr>
<tr>
<td> 17. </td>
<td>
<input type="text" name="installment17" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date10" class="tcal span4" />
</td>
</tr>
<tr>
<td> 18. </td>
<td>
<input type="text" name="installment18" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date18" class="tcal span4" />
</td>
</tr>
<tr>
<td> 19. </td>
<td>
<input type="text" name="installment19" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date19" class="tcal span4" />
</td>
</tr>
<tr>
<td> 20. </td>
<td>
<input type="text" name="installment20" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date20" class="tcal span4" />
</td>
</tr>
<tr>
<td> 21. </td>
<td>
<input type="text" name="installment21" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date21" class="tcal span4" />
</td>
</tr>
<tr>
<td> 22. </td>
<td>
<input type="text" name="installment22" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date22" class="tcal span4" />
</td>
</tr>
<tr>
<td> 23. </td>
<td>
<input type="text" name="installment23" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date23" class="tcal span4" />
</td>
</tr>
<tr>
<td> 24. </td>
<td>
<input type="text" name="installment24" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date24" class="tcal span4" />
</td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" name="save" id="save" value="Save" class="btn btn-info span3" />
<input type="hidden" readonly="readonly" name="roll_no" value="<?php echo $roll_no; ?>" class="span5" />
</td>
<td></td>
</tr>
</thead>
</table>
</form>
这里我没有得到如何将它存储在该表中。实际上,所有24个输入都不是强制性的。如果用户只填充2,那么它也应该将其存储在数据库表中。
我试着这样做
if(isset($_POST['save']))
{
$roll_no = $_POST['roll_no'];
$ins_amt1 = $_POST['installment1'];
$due_date1 = $_POST['due_date1'];
$ins_amt2 = $_POST['installment2'];
$due_date2 = $_POST['due_date2'];
$ins_amt3 = $_POST['installment3'];
$due_date3 = $_POST['due_date3'];
$ins_amt4 = $_POST['installment4'];
$due_date4 = $_POST['due_date4'];
$ins_amt5 = $_POST['installment5'];
$due_date5 = $_POST['due_date5'];
$ins_amt6 = $_POST['installment6'];
$due_date6 = $_POST['due_date6'];
$ins_amt7 = $_POST['installment7'];
$due_date7 = $_POST['due_date7'];
$ins_amt8 = $_POST['installment8'];
$due_date8 = $_POST['due_date8'];
$ins_amt9 = $_POST['installment9'];
$due_date9 = $_POST['due_date9'];
$ins_amt10 = $_POST['installment10'];
$due_date10 = $_POST['due_date10'];
$ins_amt11 = $_POST['installment11'];
$due_date11 = $_POST['due_date11'];
$ins_amt12 = $_POST['installment12'];
$due_date12 = $_POST['due_date12'];
$ins_amt13 = $_POST['installment13'];
$due_date13 = $_POST['due_date13'];
$ins_amt14 = $_POST['installment14'];
$due_date14 = $_POST['due_date14'];
$ins_amt15 = $_POST['installment15'];
$due_date15 = $_POST['due_date15'];
$ins_amt16 = $_POST['installment16'];
$due_date16 = $_POST['due_date16'];
$ins_amt17 = $_POST['installment17'];
$due_date17 = $_POST['due_date17'];
$ins_amt18 = $_POST['installment18'];
$due_date18 = $_POST['due_date18'];
$ins_amt19 = $_POST['installment19'];
$due_date19 = $_POST['due_date19'];
$ins_amt20 = $_POST['installment20'];
$due_date20 = $_POST['due_date20'];
$ins_amt21 = $_POST['installment21'];
$due_date21 = $_POST['due_date21'];
$ins_amt22 = $_POST['installment22'];
$due_date22 = $_POST['due_date22'];
$ins_amt23 = $_POST['installment23'];
$due_date23 = $_POST['due_date23'];
$ins_amt24 = $_POST['installment24'];
$due_date24 = $_POST['due_date24'];
$items = array();
$installment[] =array($ins_amt1, $ins_amt2, $ins_amt3, $ins_amt4, $ins_amt5, $ins_amt6, $ins_amt7, $ins_amt8, $ins_amt9, $ins_amt10, $ins_amt11, $ins_amt12, $ins_amt13, $ins_amt14, $ins_amt15, $ins_amt16, $ins_amt17, $ins_amt18, $ins_amt19, $ins_amt20, $ins_amt21, $ins_amt22, $ins_amt23, $ins_amt24);
//$in_values= serialize($installment);
$due_date[] = array($due_date1, $due_date2, $due_date3, $due_date4, $due_date5, $due_date6, $due_date7, $due_date8, $due_date9, $due_date10, $due_date11, $due_date12, $due_date13, $due_date14, $due_date15, $due_date16, $due_date17, $due_date18, $due_date19, $due_date20, $due_date21, $due_date22, $due_date23, $due_date24);
//$in_dates= serialize($due_date);
//$s1 = "insert into installment(id, fee_id, student_id, amount, due_date, paid_date, status, rec_no) values ('', ".$fee_id.", '".$roll_no."', ".$in_values.", '".$in_dates."', '', 'unpaid', ''";
foreach($installment as $row_key => $value)
{
$item = $value;
$uom = $due_date[$row_key];
$items[] = sprintf("(%d, %d, '%s', %d, '%s', '%s', '%s', '%s')", '',
$fee_id,
mysql_real_escape_string($roll_no),
intval($item),
$uom,
'',
'',
''
);
}
$msql = 'INSERT INTO installment (id, fee_id, student_id, amount, due_date, paid_date, status, rec_no) VALUES '.implode(', ', $items);
但它只需要一个数据。有人可以建议吗。 数据必须像这样保存:
答案 0 :(得分:0)
正常的INSERT语句应如下所示:
INSERT INTO table_name (column1,column2,column3,...)
VALUES (value1,value2,value3,...);
所以尝试改变
$msql = 'INSERT INTO installment (id, fee_id, student_id, amount, due_date, paid_date, status, rec_no) VALUES '.implode(', ', $items);
要:
$values = implode(', ', $items);
$msql = 'INSERT INTO installment (id, fee_id, student_id, amount, due_date, paid_date, status, rec_no) VALUES ('.$values.');
不要忘记实际运行sql命令。我在你的脚本中没有看到任何地方:)