gpt4 book ai didi

php - 从多个复选框发布php mysql

转载 作者:行者123 更新时间:2023-11-29 05:23:17 25 4
gpt4 key购买 nike

我的表单数据列出了我的表格示例 10 条记录。

<td class='table-checkbox'><input type="checkbox" name="product[]" value="1" class='selectable-checkbox'></td>
<td><div class="input-mini">
<input type="text" id="spinnn" name="quantity[]" value="5" class='spinner'/>
</div>
</td>
</tr>

..........

我的 php 代码

$carino = $_POST['carino']; 
$quantity = $_POST['quantity'];
$product = $_POST['product'];
foreach($product as $product){
foreach($quantity as $quantity ){
$sql = "INSERT INTO mytable (product,quantity,cno) VALUES ('$product','$quantity','$carino')";
mysql_query($sql);
}}

我想将此数据插入到我的表中。但是我的 foreach 是错误的,我该怎么办?

产品独一无二

my table

product - quantity - cno
1 5 2
2 10 2

http://pastie.org/private/nwrrinnxlrumt6p3kuyq#11,13-14,19

最佳答案

这个:

<?php 

if(isset($_POST['submit'])) {

$carino = "2";

$adet = $_POST['adet'];
$urunno = $_POST['urunno'];
$total = count($_POST['adet']);

echo '<hr>';

foreach ($urunno as $checked)
{
$value = $checked - 1;
echo "Value of Urunno: $checked: Adet: $adet[$value] <br>";
echo "INSERT INTO member_interests
(`urun`,`adet`,'carino')
VALUES
('$checked','$adet[$value]','$carino')<br>";
}
}
?>

<tr>
<form method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
<td class='table-checkbox'><input type="checkbox" name="urunno[]" value="1">Product One</td>
<input type="text" id="spinnn" name="adet[]" class='spinner'/>
<td class='table-checkbox'><input type="checkbox" name="urunno[]" value="2">Product Two</td>
<input type="text" id="spinnn" name="adet[]" class='spinner'/>
<td class='table-checkbox'><input type="checkbox" name="urunno[]" value="3">Product Three</td>
<input type="text" id="spinnn" name="adet[]" class='spinner'/>
<td><div class="input-mini">
<input type="submit" name="submit" value="run" />
</form>
</div>
</td>
</tr>
</tbody>
</table>
</div>

输出:

Value of Urunno: 2: Adet: 2 
INSERT INTO member_interests (`urun`,`adet`,'carino') VALUES ('2','2','2')
Value of Urunno: 3: Adet: 3
INSERT INTO member_interests (`urun`,`adet`,'carino') VALUES ('3','3','2')

关于php - 从多个复选框发布php mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23114716/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com