0
我試圖通過一個while循環創建多個複選框創建一個數組。複選框被命名爲「to_delete[1]
」,「to_delete[2]
」,等等,等等 數組聲明我已經試過有這些:PHP - 試圖創建一個複選框數組,
$toDelete = array($_POST['to_delete']);
$toDelete = array($_POST['to_delete'][]);
到veryify有一個數組,我去打印,但發現這是空的print_r($toDelete)
。我究竟做錯了什麼?下面的代碼是 。是的,我正在做這個程序,然後將重寫爲OOP。 非常感謝有這方面的幫助!
$showQ = "SELECT * FROM urls";
$result = mysql_query($showQ);
$numRows = mysql_num_rows($result);
$row = mysql_fetch_array($result);
if(!$result) {
mysql_error();
} else {
echo "<form action='".$_SERVER["PHP_SELF"]."' method='post'>";
$i=0;
while($row = mysql_fetch_array($result)) {
echo "<input type='text' class='manId' name='manId[]' value=" . $row['id'] . " />";
echo "<input type='text' class='url' name='url[]' value=" . $row['url'] . " />";
echo "<input type='checkbox' name='to_delete[" .$i. "]' /><br/>\n";
$i++;
}
echo "<input type='submit' value='delete' name='submit' />";
echo "</form>";
}
$toDelete = array($_POST['to_delete[]']);
print_r($toDelete);
最後,我想遍歷數組,看看哪些檢查,然後從表中刪除相應的行。
以print_r($ _ POST)開頭,查看是否有任何內容傳輸,然後更新您的問題。 – 2011-12-28 18:39:00
當你print_r($ _ POST [「to_delete」])時會發生什麼; ? – Jim 2011-12-28 18:39:12