猿问

PHP动态列表检索返回未定义索引

我一直在进行测试和练习,这是个人练习的一部分,但是,我陷入了以下要通过JavaScript添加项目列表的问题,提交后,我想验证然后存储添加的列表。但是,一旦提交,我将得到一个错误的Unidentified索引,好像该值未按isset函数检查的那样提交,并且始终返回空值。在进一步查看StackOverflow之后,我发现有些是指HTML结构。因此,我将HTML最小化为如下所示:


<!doctype html>

<html>



<head>

   <!-- Required meta tags -->

   <meta charset="utf-8">

   <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

   <!-- Bootstrap CSS -->

   <link rel="stylesheet" href="assets/vendor/bootstrap/css/bootstrap.min.css">

   <link href="assets/vendor/fonts/circular-std/style.css" rel="stylesheet">

     <link rel="stylesheet" href="assets/libs/css/customeStyle.css">

   <link rel="stylesheet" href="assets/libs/css/style.css">

   <link rel="stylesheet" href="assets/vendor/fonts/fontawesome/css/fontawesome-all.css">

   <title>Concept - Bootstrap 4 Admin Dashboard Template</title>


</head>


<body>

   <!-- ============================================================== -->

   <!-- main wrapper -->

   <!-- ============================================================== -->

       <?php //include("navBar.php"); ?> 

       <!-- ============================================================== -->

       <!-- left sidebar -->

       <!-- ============================================================== -->

       <?php //include("SlideBar.php"); ?>

       <!-- ============================================================== -->

       <!-- end left sidebar -->

       <!-- ============================================================== -->

       <!-- ============================================================== -->

       <?php

         if(isset($_POST["submit"])){

           //$test = $_POST["patName"];

           if(isset($_POST["medAdded0"])){

              //echo $value;

             $listName= $_POST["medAdded0"];

             echo '<script language="javascript">';

             echo 'alert("'.$listName.'")';

             echo '</script>';

             echo $listName;

           }


跃然一笑
浏览 154回答 1
1回答

拉莫斯之舞

您已经写过:&nbsp; &nbsp; &nbsp; &nbsp;if(isset($_POST["medAdded0"])){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //echo $value;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$listName= $_POST["medAdded0"];&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;echo '<script language="javascript">';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;echo 'alert("'.$listName.'")';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;echo '</script>';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;echo $listName;&nbsp; &nbsp; &nbsp; &nbsp;}else {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //echo $value;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;echo '<script language="javascript">';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;echo 'alert("still empty")';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;echo '</script>';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;echo $_POST["medAdded0"];&nbsp; &nbsp; &nbsp; &nbsp;}未设置else时执行该块$_POST["medAdded0"]。因此,尝试在此处回显是没有意义的。摆脱界限&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;echo $_POST["medAdded0"];
随时随地看视频慕课网APP
我要回答