Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/73.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.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 注意:未定义索引:_Php_Html_Sql - Fatal编程技术网

Php 注意:未定义索引:

Php 注意:未定义索引:,php,html,sql,Php,Html,Sql,这是带有日期选择器的main.php,它指向index.php,在那里我有一个包含数据的表。它在我选择日期时起作用,但是当我对index.php页面进行一些更改时,例如:编辑数据,或者如果我直接转到index.php我会得到: 注意:第112行/Applications/XAMPP/xamppfiles/htdocs/zeta/index.php中未定义的索引:arr_date index.php <?php include 'database.php'; $selected_

这是带有日期选择器的main.php,它指向
index.php
,在那里我有一个包含数据的表。它在我选择日期时起作用,但是当我对
index.php
页面进行一些更改时,例如:编辑数据,或者如果我直接转到
index.php
我会得到:

注意:第112行/Applications/XAMPP/xamppfiles/htdocs/zeta/index.php中未定义的索引:arr_date


index.php

 <?php
 include 'database.php';

 $selected_date= $_POST['arr_date'];

 $reponse = $bdd->query("SELECT * FROM live where 
 arr_date='$selected_date'");

while ($row = $reponse->fetch())
{
?>

当然,如果直接转到index.php,这是一个没有表单数据的新请求

你应该检查一下表格是否已提交

if(isset($_POST['arr_date'])) {
    //do stuff
}

当然,如果直接转到index.php,它是一个没有表单数据的新请求

你应该检查一下表格是否已提交

if(isset($_POST['arr_date'])) {
    //do stuff
}
使用
isset()
empty()

使用
isset()
empty()


您需要检查变量是否已设置

如果设置了,则只需继续

更正代码:

<?php
include 'database.php';
if (isset($_POST['arr_date'])) {
 $selected_date= $_POST['arr_date'];
 $reponse = $bdd->query("SELECT * FROM live where 
 arr_date='$selected_date'");
 while ($row = $reponse->fetch()) {
  // While code
 }
}
?>
<?php
 include 'database.php';

 $selected_date= isset($_POST['arr_date'])?$_POST['arr_date']:"";
 if(!empty($selected_date)){
 $reponse = $bdd->query("SELECT * FROM live where 
 arr_date='$selected_date'");

  while ($row = $reponse->fetch())
  {
    // Do your stuff here;
   }
 }
?>
<?php
 include 'database.php';
 $selected_date= "";//set select date to blank
 if(isset($_POST['arr_date']))
 {
     $selected_date= $_POST['arr_date'];
     $reponse = $bdd->query("SELECT * FROM live where arr_date='$selected_date'");

    while ($row = $reponse->fetch())
    {

       // Do your stuff here;
       }
     }
?>

您需要检查变量是否已设置

如果设置了,则只需继续

更正代码:

<?php
include 'database.php';
if (isset($_POST['arr_date'])) {
 $selected_date= $_POST['arr_date'];
 $reponse = $bdd->query("SELECT * FROM live where 
 arr_date='$selected_date'");
 while ($row = $reponse->fetch()) {
  // While code
 }
}
?>
<?php
 include 'database.php';

 $selected_date= isset($_POST['arr_date'])?$_POST['arr_date']:"";
 if(!empty($selected_date)){
 $reponse = $bdd->query("SELECT * FROM live where 
 arr_date='$selected_date'");

  while ($row = $reponse->fetch())
  {
    // Do your stuff here;
   }
 }
?>
<?php
 include 'database.php';
 $selected_date= "";//set select date to blank
 if(isset($_POST['arr_date']))
 {
     $selected_date= $_POST['arr_date'];
     $reponse = $bdd->query("SELECT * FROM live where arr_date='$selected_date'");

    while ($row = $reponse->fetch())
    {

       // Do your stuff here;
       }
     }
?>

尝试查看是否设置了post数据

<?php
 include 'database.php';
 $selected_date= "";//set select date to blank
 if(isset($_POST['arr_date']))
 {
     $selected_date= $_POST['arr_date'];
     $reponse = $bdd->query("SELECT * FROM live where arr_date='$selected_date'");

    while ($row = $reponse->fetch())
    {
    }//end of while
}
?>

尝试查看是否设置了post数据

<?php
 include 'database.php';
 $selected_date= "";//set select date to blank
 if(isset($_POST['arr_date']))
 {
     $selected_date= $_POST['arr_date'];
     $reponse = $bdd->query("SELECT * FROM live where arr_date='$selected_date'");

    while ($row = $reponse->fetch())
    {
    }//end of while
}
?>

直接访问未定义的数组键(数组索引)会导致

“注意:未定义索引:KEY_NAME”

解决方案:

  • 首先检查键是否存在
    isset($\u POST['key'])

  • 如果存在,请使用

  • 代码:


    直接访问未定义的数组键(数组索引)会导致

    “注意:未定义索引:KEY_NAME”

    解决方案:

  • 首先检查键是否存在
    isset($\u POST['key'])

  • 如果存在,请使用

  • 代码:


    您必须显示完整的代码。不管您是如何直接像这样从数组中获取值的$val=$\u POST['arr\u date'],必须使用isset()函数检查变量是否设置为这样

    if(isset($_POST['arr_date'])){
       $var = $_POST['arr_date'];
    }
    

    您必须显示完整的代码。不管您是如何直接像这样从数组中获取值的$val=$\u POST['arr\u date'],必须使用isset()函数检查变量是否设置为这样

    if(isset($_POST['arr_date'])){
       $var = $_POST['arr_date'];
    }
    

    您的代码几乎正确,但您还需要编写验证,如下所示:

    第一种方法:

    <?php
    include 'database.php';
    if (isset($_POST['arr_date'])) {
     $selected_date= $_POST['arr_date'];
     $reponse = $bdd->query("SELECT * FROM live where 
     arr_date='$selected_date'");
     while ($row = $reponse->fetch()) {
      // While code
     }
    }
    ?>
    
    <?php
     include 'database.php';
    
     $selected_date= isset($_POST['arr_date'])?$_POST['arr_date']:"";
     if(!empty($selected_date)){
     $reponse = $bdd->query("SELECT * FROM live where 
     arr_date='$selected_date'");
    
      while ($row = $reponse->fetch())
      {
        // Do your stuff here;
       }
     }
    ?>
    
    <?php
     include 'database.php';
     $selected_date= "";//set select date to blank
     if(isset($_POST['arr_date']))
     {
         $selected_date= $_POST['arr_date'];
         $reponse = $bdd->query("SELECT * FROM live where arr_date='$selected_date'");
    
        while ($row = $reponse->fetch())
        {
    
           // Do your stuff here;
           }
         }
    ?>
    

    您的代码几乎正确,但您还需要编写验证,如下所示:

    第一种方法:

    <?php
    include 'database.php';
    if (isset($_POST['arr_date'])) {
     $selected_date= $_POST['arr_date'];
     $reponse = $bdd->query("SELECT * FROM live where 
     arr_date='$selected_date'");
     while ($row = $reponse->fetch()) {
      // While code
     }
    }
    ?>
    
    <?php
     include 'database.php';
    
     $selected_date= isset($_POST['arr_date'])?$_POST['arr_date']:"";
     if(!empty($selected_date)){
     $reponse = $bdd->query("SELECT * FROM live where 
     arr_date='$selected_date'");
    
      while ($row = $reponse->fetch())
      {
        // Do your stuff here;
       }
     }
    ?>
    
    <?php
     include 'database.php';
     $selected_date= "";//set select date to blank
     if(isset($_POST['arr_date']))
     {
         $selected_date= $_POST['arr_date'];
         $reponse = $bdd->query("SELECT * FROM live where arr_date='$selected_date'");
    
        while ($row = $reponse->fetch())
        {
    
           // Do your stuff here;
           }
         }
    ?>
    



    第一次尝试打印
    $\u POST
    ,并使用
    isset()
    函数处理这类事情的可能副本。您的SQL易受注入攻击。了解如何使用参数化查询和准备好的语句。对风险有一个清晰(且幽默)的解释,加上一些关于如何正确操作的信息,包括在PHP中。第一次尝试打印
    $\u POST
    ,并使用
    isset()
    函数处理这类事情可能会重复。您的SQL易受注入攻击。了解如何使用参数化查询和准备好的语句。有一个清晰(和幽默)的风险解释,加上一些关于如何正确操作的信息,包括在PHP中。你的代码是错误的。当您首先检查值(在isset之前)时,它将发出一个“未定义索引”。我没有在
    isset
    之前检查值。我将空白数据分配给
    $selected_date
    ,因为如果在代码下方使用,并且如果未达到
    语句,则不会生成任何错误。
    $selected_date=“”是相当多余的,我认为你的代码是错误的。当您首先检查值(在isset之前)时,它将发出一个“未定义索引”。我没有在
    isset
    之前检查值。我将空白数据分配给
    $selected_date
    ,因为如果在代码下方使用,并且如果未达到
    语句,则不会生成任何错误。
    $selected_date=“”
    是相当多余的我想Thank you@RJParikhThank you@RJParikhthx正在工作没有更多的错误但页面上没有更多的数据即使刷新,我也必须返回并刷新以显示您想要显示的数据?在索引页上@SCUNJAW当您单击submit时,表单将重定向到index.php页面,它肯定会在提交后为您提供post数据并将其显示在index.phpYes上。没错,我有post数据,但当我在index.php表单提交后在页面上编辑内容时,在完成
    if(isset($\u post['arr\u date'])后编写其他代码
    然后检查。。检查编辑的答案@scunjathx正在工作没有更多错误,但页面上没有更多数据即使刷新,我也必须返回并刷新以显示您要显示的数据?在索引页上@SCUNJAW当您单击submit时,表单将重定向到index.php页面,它肯定会在提交后为您提供post数据并将其显示在index.phpYes上。没错,我有post数据,但当我在index.php表单提交后在页面上编辑内容时,在完成
    if(isset($\u post['arr\u date'])后编写其他代码
    然后检查。。检查编辑的答案@scunjathx正在工作没有更多的错误,但页面上没有更多的数据即使刷新,我必须返回并刷新以显示data@scunja除非你从另一个页面提交表格,否则当然不会有更多的数据。直接访问index.php而不提交表单是没有意义的,因为它本质上依赖于来自表单的数据。没有理由以其他方式查看页面。@ADyson thx但如何更正这些内容?我真的不知道know@scunja我不知道你想纠正什么?如果您的index.php依赖于表单提交的数据,那么除了提交表单之外,您为什么还要尝试以其他方式访问它呢?是的,但在表单提交之后,我想在index.php上搜索,并在同一页面上执行其他表单操作(index.php)。thx不会再出现错误,但即使刷新,页面上也不会出现更多数据,我得回去一趟