我想在单个提交按钮中存储多行。这是购物车页面 在这里我添加了简单的代码。我想在数据库中存储多行
HTML
<form class="form-horizontal" name="project_form" id="project_form" action="{url r="cart#prepare"}" method="post">
{foreach from=$user item="user"}
<div class="col-4 heads"> NAME </div>
<div class="col-8"> <input type="text" name="name" id="name" placeholder="name" value="{$user.user_name}" > </div>
<div class="col-4 heads"> Email </div>
<div class="col-8"> <input type="text" name="email" id="email" placeholder="email" value="{$user.email}" > </div>
<div class="col-4 heads"> Mobile </div>
<div class="col-8"> <input type="text" name="cell" id="cell" placeholder="mobile no" value="{$user.mobile}" > </div>
{/foreach}
<div class="col-4 heads"> ADDRESS LINE 1 </div>
<div class="col-8"> <input type="text" name="address1" id="address1" placeholder="address1" > </div>
<div class="col-4 heads"> ADDRESS LINE 2 </div>
<div class="col-8"> <input type="text" name="address2" id="address2" > </div>
<div class="col-4 heads"> CITY </div>
<div class="col-8"> <input type="text" name="city" id="city" placeholder="city" > </div>
<div class="col-4 heads"> STATE </div>
<div class="col-8"> <input type="text" name="state" id="state" placeholder="state" > </div>
<input type="text" id="iinc" name="iinc" value="3">
不要与html混淆。怀疑只在这里。仅在PHP函数中是。
public function prepare()
{
if(!$GLOBALS['user_info'])
{
app_redirect(url("user#login"));
}
else
{
$name = $_REQUEST['name'];
$iinc = $_REQUEST['iinc'];
for($i=1; $i <= $iinc; $i++)
{
$order_id[$i] = mt_rand(100000, 999999);
$Amount[$i]=$_REQUEST['amount'];
$list = $GLOBALS['db']->query("insert into payment(name,order_id,amount) Values('".$name."','".order_id[$i]."','".$Amount[$i]."');
}
}
}
答案 0 :(得分:1)
请更改您的代码
$order_id=array();
$Amount=array();
for($i=0; $i < $iinc; $i++)
{
$order_id[$i] = mt_rand(100000, 999999);
$Amount[$i]=$_REQUEST['amount'];
$list = $GLOBALS['db']->query("insert into payment(name,order_id,amount) Values('".$name."','".order_id[$i]."','".$Amount[$i]."');
}
答案 1 :(得分:0)
你在for loop
检查此
for($i=1; $i > $iinc; $i++)
应该是这样的
for($i=1; $i < $iinc; $i++)
或强>
for($i=1; $i <= $iinc; $i++)