加我有如下代碼,使表:編寫PHP代碼中動態由JavaScript
echo("<script type='text/javascript'>
var table = document.getElementById('show_member');
// Create an empty <tr> element and add it to the 1st position of the table:
var row = table.insertRow(i);
i = i+1;
// Insert new cells (<td> elements) at the 1st and 2nd position of the new <tr> element:
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
var cell3 = row.insertCell(2);
var cell4 = row.insertCell(3);
var cell5 = row.insertCell(4);
var cell6 = row.insertCell(5);
var cell7 = row.insertCell(6);
var cell8 = row.insertCell(7);
var cell9 = row.insertCell(8);
var cell10 = row.insertCell(9);
var cell11 = row.insertCell(10);
// Add some text to the new cells:
cell1.innerHTML = '$name';
cell2.innerHTML = '$name2';
cell3.innerHTML = '$lastname';
cell4.innerHTML = '$lastname2';
cell5.innerHTML = '$mellicode';
cell6.innerHTML = '$estekhdamnum';
cell7.innerHTML = '$email';
cell8.innerHTML = '$username';
cell9.innerHTML = '$password';
cell10.innerHTML = '$id';
var checkbox = document.createElement('INPUT');
***checkbox.type = 'checkbox';
checkbox.name = 'mark[]';
checkbox.value = i-1;
cell11.appendChild(checkbox);***
</script>");
和下方的按鈕:
<div class="container">
<input type="button" class="form-control" name = "karbar" id ="check" value="افزودن به لیست کاربران"onclick="add_karbar1()"/><br><br>
</div>
以下是我的PHP代碼更新表格
<?php
if(isset($_POST['karbar'])){
//echo "<script>alert('was selected')</script>";
foreach($_REQUEST['mark'] as $value){
echo "<script>alert('$value was selected');</script>";
}
}
?>
它給了我這個錯誤,爲什麼?
說明:未定義指數:標記在E:\ Xampp_installed \ htdocs中\上線路卡\ add_karbar.php 236
警告:在E中的foreach()提供參數無效:\ Xampp_installed \ htdocs中\卡\ add_karbar.php on line 23
如何識別選中的複選框併爲每行中的每個選中的複選框執行php代碼?
感謝
是什麼'$ _REQUEST'是什麼樣子? – charlietfl
你是什麼意思? 我在其他網站搜索過,他們說你應該使用$ _REQUEST識別複選框並在其中寫入php代碼。 –
很好,但如果index''mark''未定義,則需要檢查'$ _REQUEST'值來查看原因。只是傾倒整個事情,看看它是否看起來像你期望它 – charlietfl