简体   繁体   English

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

[英]I can't pass some value from html checkbox array to my php page?

I created the product management system that use HTML+PHP+SQL+JS.But it's have a problem some value can't pass to php page to SQL query.I can't find any bug in my code because some data can do that normally. 我创建了使用HTML + PHP + SQL + JS的产品管理系统,但是存在一个问题,即某些值无法传递到php页面以进行SQL查询。我在代码中找不到任何错误,因为某些数据可以做到这一点一般。 my system use the checkbox array to choose each product that i want to do with them 我的系统使用复选框数组来选择我要使用它们的每个产品

echo "<td><input type=\"checkbox\" name=\"ProductKey[]\" value=\"".$Key."\"/></td>";

and pass them to any target by javascript like this 并通过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>

in php page that receive value to sql query 在PHP页面中接收到SQL查询的值

foreach ($_POST['ProductKey'] as $Key){
....
}

The Example data that can pass 可以通过的示例数据

ProductKey | Size | Colour | Price | Cost | Quantity | Customer | ProductKey | AccountKey
DK9973 | 42 | Black | 550 | 280 |1 | ram35 | 57872 | 128

Example data that can't pass 无法通过的示例数据

ProductKey | Size | Colour | Price | Cost | Quantity | Customer | ProductKey | AccountKey
A056 | 40 | Brown | 350 | 220 |1 | ram35 | 58784 | 133

some javascript button function 一些javascript按钮功能

 function OnButtonDelete() {
    document.myform.action = "delete.php";
    document.myform.target = "_self";
    document.myform.submit();
    return true;  
  }

Thanks for all answer ,If you want more code please tell me :) 感谢您提供所有答案,如果您需要更多代码,请告诉我:)

If your checkbox is not checked, it will not exist in the php page who receive the post data. 如果未选中您的复选框,则接收帖子数据的php页面中将不存在该复选框。

Just test : 只是测试:

if(isset($_POST['ProductKey'])){
  //Checkbox checked
} else {
  //Checkbox not checked
}

Now, I solved it!! 现在,我解决了! it should be the html checkbox maximum in one form. 它应该是一种形式的html复选框最大值。 I tried to make the search input that query from ProductID it make the number of checkbox in one form decrease but,now it work for all product. 我试图使从ProductID查询的搜索输入使一种形式的复选框数量减少,但现在它适用于所有产品。

I don't sure about this solution,but it's work. 我不确定这种解决方案,但是可以。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM