Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我的for each循环缺少数组中的第一个数据集_Php_Html_For Loop - Fatal编程技术网

Php 我的for each循环缺少数组中的第一个数据集

Php 我的for each循环缺少数组中的第一个数据集,php,html,for-loop,Php,Html,For Loop,我正在从表单发送此数据集。每个数据集都完全相同,但只有事件[1]和事件[2]在插入(我使用不同的数据集验证了这一点)。无论我添加了多少个数组,事件[0]数据从未插入到我的数据库中,这都保持不变 event[0][equipTypeUpdate]: 2 event[0][productTypeUpdate]: 33 event[0][serialNumUpdate]: 123456 event[0][assestNumUpdate]: 123456 event[0][payNumUpdate]:

我正在从表单发送此数据集。每个数据集都完全相同,但只有事件[1]和事件[2]在插入(我使用不同的数据集验证了这一点)。无论我添加了多少个数组,事件[0]数据从未插入到我的数据库中,这都保持不变

event[0][equipTypeUpdate]: 2
event[0][productTypeUpdate]: 33
event[0][serialNumUpdate]: 123456
event[0][assestNumUpdate]: 123456
event[0][payNumUpdate]: 1234596
event[0][warrantyEndDate]: 2020-10-05
event[0][statusUpdate]: No
event[0][installedInRoom]: No
event[0]siteNameUpdate]: 9
event[0][roomNameUpdate]: 1
event[1][equipTypeUpdate]: 2
event[1][productTypeUpdate]: 33
event[1][serialNumUpdate]: 123456
event[1][assestNumUpdate]: 123456
event[1][payNumUpdate]: 123156
event[1][warrantyEndDate]: 2020-10-05
event[1][statusUpdate]: No
event[1][installedInRoom]: No
event[1][siteNameUpdate]: 9
event[1][roomNameUpdate]: 1
event[2][equipTypeUpdate]: 2
event[2][productTypeUpdate]: 33
event[2][serialNumUpdate]: 123456
event[2][assestNumUpdate]: 123456
event[2][payNumUpdate]: 123156
event[2][warrantyEndDate]: 2020-10-05
event[2][statusUpdate]: No
event[2][installedInRoom]: No
event[2][siteNameUpdate]: 9
event[2][roomNameUpdate]: 1


这是我的foreach循环,循环遍历数组,将它们保存为变量插入数据库。我认为这是一个错误的地方}这里有一个问题,但似乎无法解决。 谢谢你的帮助

if(is_post_request()) {
  if (isset($_POST["event"])) {
              $events = $_POST["event"];
  }
  foreach ($events as $event) {
    // code...
  $equipIdValue = $event['equipTypeUpdate'];
  $prodValue= $event['productTypeUpdate'];
  $serialValue= $event['serialNumUpdate'];
  $assetValue = $event['assestNumUpdate'];
  $paymentValue = $event['payNumUpdate'];
  $warrantyValue = $event["warrantyEndDate"];
  $installedValue = $event["installedInRoom"];
  $buildValue = $event["siteNameUpdate"];
  $statusValue = $event["statusUpdate"];
  $roomValue = $event["roomNameUpdate"];

  $timeStamWar = strtotime($warrantyValue);
  $siteValue = $_SESSION['location'];
  create_inventory($equipIdValue ,$prodValue ,$siteValue, $buildValue, $statusValue , $serialValue, $roomValue, $installedValue, $assetValue, $paymentValue, $timeStamWar);
}
 echo "New record created successfully";
 $lastInsertId = mysqli_insert_id($db);
redirect_to("../Pages/my_site_stock.php?id=$timeStamWar");

}
else{
      // INSERT FAILED
      echo mysqli_error($db);
      db_disconnect($db);
      exit;
    }
编辑:

根据评论中的建议,我对$events和$event进行了vardump。 他们似乎没有获得事件[0]数据,这很奇怪,因为网络部分下的chrome开发者工具显示了我的表单post数据发送

event[0][equipTypeUpdate]: 1
event[0][productTypeUpdate]: 2
event[0][serialNumUpdate]: 123456
event[0][assestNumUpdate]: 123456
event[0][payNumUpdate]: 1234596
event[0][warrantyEndDate]: 2020-10-12
event[0][statusUpdate]: No
event[0][installedInRoom]: No
event[0]siteNameUpdate]: 9
event[0][roomNameUpdate]: 3

编辑2.0

A few of my variables were single quotes and some were doubles.
Issue is fixed thanks for the help

这里需要做的就是调试每个步骤。在
foreach($events as$event)之前{
转储
$events
的值,并确保它们都在那里

如果是,则将进入
create\u inventory
功能的所有值转储出去


您的问题没有一个正确答案,因为可能有多个地方没有数据,但您的帖子数据很可能不包含第一个数组

,非常感谢,这似乎是问题所在。$events变量缺少所有事件[0]chrome developer tools提供的奇怪数据表明它正在发送。我的一些变量是单引号,一些是双引号。问题已经解决了。感谢您的帮助很高兴您对其进行了排序!
A few of my variables were single quotes and some were doubles.
Issue is fixed thanks for the help