什么原因导致:“注意:未初始化的字符串偏移量"出现? [英] What causes: "Notice: Uninitialized string offset" to appear?

查看:15
本文介绍了什么原因导致:“注意:未初始化的字符串偏移量"出现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用户填写的表单,表单上有多个相同的字段,例如项目名称"、项目日期"、类别"等.根据用户提交的表单数量,我的目标是:

I have a form that users fill out, and on the form there are multiple identical fields, like "project name", "project date", "catagory", etc. Based on how many forms a user is submitting, my goal is to:

  1. 遍历表单数量
  2. 创建单独的 SQL 插入语句

但是,PHP 向我抛出一个我似乎不明白的通知:

However, PHP throws me a NOTICE that I don't seem to understand:

注意:

注意:未初始化的字符串偏移量:1 ...dataPasser.php 第 90 行

Notice: Uninitialized string offset: 1 ...dataPasser.php on line 90

PHP

$myQuery = array();

if ($varsCount != 0)
{
  for ($i=0; $i <= $varsCount; $i++)
  {
    $var = "insert into projectData values ('" . $catagory[$i] . "', '" .  $task[$i] . "', '" . $fullText[$i] . "', '" . $dueDate[$i] . "', null, '" . $empId[$i] ."')";
    array_push($myQuery, $var);     
  }
}

我遇到了对这个问题的引用,但它们并不准确,我无法推断出实际问题的根源.如果您能帮助我理解导致数组无法正确初始化的原因,我将不胜感激.

There are references to this issue I am having, but they are not exact and I am having trouble deducing where the actual problem stems from. I would greatly appreciate any help in understanding what is causing the array to not initialize properly.

推荐答案

如果以下任何变量实际上是字符串或 null 而不是数组,则将发生此错误,在这种情况下使用数组语法访问它们 $var[$i] 就像尝试访问字符串中的特定字符:

This error would occur if any of the following variables were actually strings or null instead of arrays, in which case accessing them with an array syntax $var[$i] would be like trying to access a specific character in a string:

$catagory
$task
$fullText
$dueDate
$empId

简而言之,插入查询中的所有内容.

In short, everything in your insert query.

也许 $catagory 变量拼写错误?

Perhaps the $catagory variable is misspelled?

这篇关于什么原因导致:“注意:未初始化的字符串偏移量"出现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆