gpt4 book ai didi

PHP 多文本框数组

转载 作者:行者123 更新时间:2023-11-29 07:31:34 25 4
gpt4 key购买 nike

我有文本框数组

<form method="POST">
<input type="text" name="partnumber[]" value="1234">
<input type="text" name="desc[]" value="used">
<input type="text" name="qty[]" value="24">
<input type="text" name="partnumber[]" value="2345">
<input type="text" name="desc[]" value="good">
<input type="text" name="qty[]" value="31">
<input type="text" name="partnumber[]" value="3456">
<input type="text" name="desc[]" value="brand new">
<input type="text" name="qty[]" value="22">
<input type="submit">
</form>

发布后,我想像这样插入到我的数据库中。具有相同的 ref_id。

last_insert_id = 17;

id | ref_id | partnumber| description | quantity
1 | 17 | 1234 | used | 24
2 | 17 | 2345 | good | 31
3 | 17 | 3456 | brand new | 22

如有任何帮助,我们将不胜感激。谢谢..

$comma  = "";
$values = "";
$last_id = 17;
foreach ($partnumber as $p) {
foreach ($desc as $d) {
foreach ($qty as $q) {
}
}
$values .= $comma."($id,$last_id,'$p','$d','$q')";
$comma = ",";
}


$sql = "INSERT INTO parts_replaced (id,last_id,partnumber,description,quantity) VALUES $values";

最佳答案

你可以像这样摆脱这个表格..

 <form method="POST">
<input type="text" name="partnumber[]" value="1234">
<input type="text" name="desc[]" value="used">
<input type="text" name="qty[]" value="24">
<input type="text" name="partnumber[]" value="2345">
<input type="text" name="desc[]" value="good">
<input type="text" name="qty[]" value="31">
<input type="text" name="partnumber[]" value="3456">
<input type="text" name="desc[]" value="brand new">
<input type="text" name="qty[]" value="22">
<input type="submit">
</form>
<?php
if(isset($_POST['partnumber']))
{
$parnumber=$_POST['partnumber'];

foreach ($parnumber as $key => $value) {
echo $value.'-'.$_POST['desc'][$key].'-'.$_POST['qty'][$key].'<br />';

//add your query here
}

}

?>

关于PHP 多文本框数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32471668/

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