【发布时间】:2012-09-24 04:29:20
【问题描述】:
我有一个表单,可以通过单击“[+]”号来增加其字段。
我用于表单的代码是 描述 数量 价格 ';
// 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="'.stripslashes($text['quantity'][$i]).'" size="4" />
</td>
<td>
<input name="text[unit]['.$i.']" id="u'.$i.'" value="'.stripslashes($text['unit'][$i]).'" size="7" /> USD
</td>
</tr>';
}
echo '
</table>
<input type="submit" name="save" value="Save" />
</form>
';
if(isset($_POST['save']))
{
echo $text['quantity']['.$i.'];
mysql_connect("localhost","root","");
mysql_select_db("rvt") or die("unable to select db");
extract($_POST);
$insert=mysql_query("insert into add(description, quantity, price) values('$text[detail][".$i."]','$text[quantity][".$i."]','$text[unit][".$i."]')");
if($insert)
{
echo "hi";
}
}
?>
我想将数据存储到数据库中。它不起作用。
请帮助我将数据存储在数据库中。
【问题讨论】:
-
@Petah 它不会在数据库中插入数据。
-
输入 echo mysql_error($db) 看看它说了什么?
-
@BenKirchner:警告在这里,警告:mysql_error():提供的参数不是 D:\wamp\www\others\addrow-form.php 中的有效 MySQL-Link 资源