我有一個表單,用戶可以在其中添加更多字段,因爲他想...如何在數據庫中存儲動態添加行的值
他可以添加1,2,3行....田..
字段被成功添加,我用的是這裏的代碼,
<?php
echo '
<form method="post" action="">
<input type="hidden" name="mod" value="'.$mod.'" />
<table style="width: 700px">
<tr>
<th>Description</th>
<th>Quantity</th>
<th>Price</th>
</tr>';
// Loop to prepare the display of 100 product lines
for ($i=0; $i<100; $i++) {
if ($text['quantity'][$i] == "") $text['quantity'][$i] = 1;
if ($text['unit'][$i] == "") $text['unit'][$i] = "0.00";
// Display only the first line
if ($nbr_ligne == 0) $nbr_ligne = 1;
if ($i >= $nbr_ligne) $display = 'style="display:none"';
echo '
<tr id="cell'.$i.'" '.$display.'>
<td>
<textarea name="text[detail]['.$i.']">'.stripslashes($text['detail'][$i]).'</textarea>
<br />
<a href="javascript:void(0)" onclick="javascript:document.getElementById(\'cell'.($i+1).'\').style.display=\'table-row\'; this.style.display=\'none\'">[+]</a>
</td>
<td>
<input name="text[quantity]['.$i.']" id="q'.$i.'" value="" size="4" />
</td>
<td>
<input name="text[unit]['.$i.']" id="u'.$i.'" value="" size="7" /> USD
</td>
</tr>';
}
echo '
</table>
<input type="submit" name="save" value="Save" />
</form>
';
?>
。
現在我想將這些字段的值存儲在數據庫中。
我用這個代碼:
if(isset($_POST['save']))
{
echo mysql_error($db);
extract($_POST);
$insert=mysql_query(" insert into add (description, quantity, price) values ('{$text['detail'][$i]}','{$text['quantity'][$i]}','{$text['unit'][$i]}')") or die("unable to insert");
}
,但它不工作。 PLZ幫助我的傢伙。我非常需要它。
你得到什麼錯誤? – Gapchoos
沒有錯誤,但值不存儲在數據庫中。 –
@Gapchoos:屏幕上顯示的輸出是「無法插入」 –