我使用HTML+PHP+SQL+JS创建了产品管理系统,但是它有一个问题 某些值无法传递到 php 页面进行 SQL 查询。我在代码中找不到任何错误,因为某些数据可以正常执行此操作。 我的系统使用复选框数组来选择我想要用它们做的每个产品
echo "<td><input type=\"checkbox\" name=\"ProductKey[]\" value=\"".$Key."\"/></td>";
并通过 JavaScript 将它们传递给任何目标,如下所示
<input type='button' id='edit' onclick="OnButtonEdit();" class = "btn btn-success" value='add'></br></br>
<input type='button' id='delete' onclick="OnButtonDelete();" class = "btn btn-warning" value='subtract'></br></br>
<input type='button' id='delete' onclick="OnButtonRemove();" class = "btn btn-danger" value='remove'></br></br>
<input type='button' id='delete' onclick="OnButtonProductbackquery();" class = "btn btn-info" value='pass back to homestock'></br>
在接收 sql 查询值的 php 页面中
foreach ($_POST['ProductKey'] as $Key){
....
}
可以通过的示例数据
ProductKey | Size | Colour | Price | Cost | Quantity | Customer | ProductKey | AccountKey
DK9973 | 42 | Black | 550 | 280 |1 | ram35 | 57872 | 128
无法通过的示例数据
ProductKey | Size | Colour | Price | Cost | Quantity | Customer | ProductKey | AccountKey
A056 | 40 | Brown | 350 | 220 |1 | ram35 | 58784 | 133
一些javascript按钮功能
function OnButtonDelete() {
document.myform.action = "delete.php";
document.myform.target = "_self";
document.myform.submit();
return true;
}
感谢您的所有回答,如果您想要更多代码,请告诉我:)
最佳答案
如果您的复选框未选中,则接收帖子数据的 php 页面中将不存在该复选框。
只是测试:
if(isset($_POST['ProductKey'])){
//Checkbox checked
} else {
//Checkbox not checked
}
关于php - 我无法将某些值从 html 复选框数组传递到我的 php 页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16147401/