php - 我无法将某些值从 html 复选框数组传递到我的 php 页面?

标签 php javascript html mysql

我使用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/

相关文章:

javascript - 我应该使用哪种方法来清理文本区域?

HTML/CSS 导航栏没有响应

php - 使用 FPDF 库生成 PDF 的问题

javascript - 用户/浏览器操作 Javascript 有多容易?

javascript - 首先通过在其他数组中包含 ID 对数组进行排序,然后按日期排序

JavaScript - 从数据库中获取值并传递给 res.render

php - 在文本框中显示两个值

php - 更新一列中的完整数组值

php - 基于角色的登录

html - Grunt/Assemble - 输出 html 缩小