我現在把input值傳到php都只能傳一個,要怎樣才能傳陣列呢?
我勾了3個選項,但她永遠只會傳最後一個值
JSP直接
String[] a = request.getParameterValues("a");
就能把input的值都抓出來
可是PHP該怎麼做呢?
附PHP程式:
<!DOCTYPE html>
<html>
<body>
<div class="container" style="padding-bottom:100px;">
<?php
require 'db_login.php';
if(isset($_POST['submit'])){
$arr[] = $_POST['a'];//我勾了3個選項,但她永遠只會傳最後一個值
echo $arr[1];
}
?>
<form id="myform" name="myform" action="delete.php" method="post" >
<div class="row mt-5 mb-5">
<?php
require 'db.php';
$sql = "SELECT * FROM myform ";
$query_sql = mysqli_query($db, $sql);
echo "
<table class='table table-bordered text-center max'>
<tr class='table-info'>
<th class='text-center' > 勾選</th>
<th class='text-center' > 業務</th>
</tr>";
while ($row = mysqli_fetch_array($result)) {
?>
<tbody id="searchTable">
<tr>
<td class="text-center align-middle" >
<input type=checkbox name='a' id='a' value="<?=$row["id"]?>">
</td>
<?php
echo ' <td class="text-center" > '.$row["sale"].'
</td>
<tr>
';
}?>
</tbody>
</table>
<button type="submit" name="submit" class="btn " >確認</button>
</div>
</form>
</div>
</body>
</html>
謝謝
你做個小網頁試以下就瞭了
html form
<input type="hidden" name="data[abc123]" value="" />
php
print_r($_POST);
print_r($_POST['data']);