2016-09-22 168 views
-2

后apeeared未定义索引我有两个步骤的形式。 create.php和create2.php。两页都是表格。在第一个表单填充后,用户按下“继续”,然后进入第二个表单,在该表单中,我将第一个表单的值存储在隐藏的输入中。填写并提交第二个表单后,我想弹出窗口,这意味着成功提交表单并将所有数据插入数据库。看来,一切工作正常,所有数据都在数据库中,但我没有弹出窗口,我得到的是未定义的索引警告关于我的隐藏输入。提交表单

确定这里是create.php代码:

<form class="formcss" method="post" action="create2.php" id="reportform" enctype="multipart/form-data"> 

    <fieldset style="background-color:white;"> 
    <legend style="font-size: 20px;">New Project</legend> 
    <br> 
    <div class="row"> 
    <div class="small-8 large-8 columns"> 
     <label>Project Code: <small style="color:red;">*</small> 

     <input type="text" name="code" maxlength="155" id="code" class="input input1 name" onkeyup="limitTextCount('code', 'divcount0', 155, 0);" onkeydown="limitTextCount('code', 'divcount0', 155, 0);" <?php if (isset($code)) echo 'value="'.$code.'"' ?>/> 

     <label class="tool tool1" for="name" style="margin-top:-8px;">Code of the project</br>e.g. ASD001</label> 
     </label> 
    </div> 
    </div> 

    <div class="row"> 
    <div class="small-8 large-8 columns"> 
     <label>Project Name: <small style="color:red;">*</small> 

     <input type="text" name="title" maxlength="155" id="title" class="input input1 name" onkeyup="limitTextCount('title', 'divcount0', 155, 0);" onkeydown="limitTextCount('title', 'divcount0', 155, 0);" <?php if (isset($title)) echo 'value="'.$title.'"' ?>/> 

     <label class="tool tool1" for="name" style="margin-top:-8px;">Title of the project</br>e.g. Leon</label> 
     </label> 
    </div> 
    </div> 
    <div class="row"> 
     <div class="small-8 large-8 columns"> 
     <label>Process    
      <div class="multiselect">    
       <div class="selectBox">     
        <select onclick="showCheckboxes()" class="input input1 name"> 
         <option>-- Select an option --</option>   
        </select> 
        <div class="overSelect"></div> 
       </div> 
       <div class="scrollable" id="checkboxes">  
       <?php 
        while ($row = mysql_fetch_array($result)) 
        { 
         $row[0] = cleanOutputData($row[0]);        
       ?>  
        <div class="row"> 
         <div class="small-12 large-12 columns"> 
         <label style="height: 37px; width:80%; float:left;"> 
         <input type="checkbox" class="checkbox" style="margin-left:5%; width:15%;" name="process[]" id=<?php echo $row[0] ?> value=<?php echo $row[0]?> /><?php echo $row[0] ?> 
         </label> 
         <label style="width:40%; margin-left:60%;"><input type="text" class="field" disabled style="width:40%;" name="numberpl[]" id=<?php echo $row[0] ?> /> 
         </label>  
         </div> 
        </div> 
       <?php 
        } 
        mysql_free_result($result); 
       ?>   
       </div> 
      </div> 
     </label> 
     </div> 
    </div> 
    <div class="row"> 
    <div class="small-8 large-8 columns"> 
     <label>Comments 
       <textarea style="resize:none;" class="input input1 name" name="remark" rows="8" cols="50" maxlength="255" id="remark" onkeyup="limitTextCount('remark', 'divcount5', 255, 0);" onkeydown="limitTextCount('remark', 'divcount5', 255, 0);"><?php if (isset($remark)) echo $remark ?></textarea> 
      <label class="tool tool1" for="name" style="left:-140px;">Further comments</label> 
     </label> 
    </div> 
    <div class="small-6 large-6 columns"> 
     <label>&nbsp;<?php if (isset($remark)){ echo "<label id='divcount5'></label>"; echo "<script>limitTextCount('remark', 'divcount5', 255, 0);</script>";} else echo "<label id='divcount5'>255 characters remaining</label>";?></label> 
    </div> 
    </div> 

    <div class="row"> 
    <div class="small-8 large-8 columns"> 
     <input type = "submit" name ="submit" style="margin-left:600px; width:150px;" class="button" onclick="userSubmitted = true;" value = "Continue"/> 

    </div> 
    </div> 

    <br/><br/> 
    </fieldset> 
</form> 

而对于第二种形式create2.php:

<?php 
    session_start(); 
    //if user haven't sign in will redirect user to login page 
    if(empty($_SESSION['login_user'])){ 
     session_destroy(); 
     header("Location: login.php"); 
    } 
    $proc = isset($_POST['process'])?$_POST['process']:''; 
    //$proc=$_POST['process']; 
    $len = count($proc); // getting length of ur array that u need to condition ur loop 

    $num = isset($_POST['numberpl'])?$_POST['numberpl']:''; 
    //$num=$_POST['numberpl']; 
    //$len2 = count($num); // getting length of ur array that u need to condition ur loop 
    include 'verification/verify_form_details2.php'; 
    require_once('inc/config.php'); 
    //include 'verification/verify_form_details.php'; 
    ob_start(); 

    $servername = "localhost"; 
    $username = "root"; 
    $password = ""; 
    $dbname = "pp"; 

    // Create connection 
    $conn = new mysqli($servername, $username, $password, $dbname); 
    // Check connection 
    if ($conn->connect_error) { 
     die("Connection failed: " . $conn->connect_error); 
    } 
?> 

<form class="formcss" method="POST" name="checkoutForm" action="create2.php#err" id="reportform" enctype="multipart/form-data"> 
    <?php 
     $res = verifyFormFields(); 
    ?> 
<!-- hidden inputs from first form(create.php) --> 
    <input type="hidden" name="holdcode" value="<?php echo isset($_POST['code'])?$_POST['code']:'';?>"> 
    <input type="hidden" name="holdtitle" value="<?php echo isset($_POST['title'])?$_POST['title']:'';?>"> 

    <?php 
     //an array of inputs 
     for($y=0;$y<$len;$y++) 
     { 
    ?> 
      <input type='hidden' name='holdprocess[]' value="<?php echo $proc[$y]?>"> 
      <input type='hidden' name='holdnumber[]' value="<?php echo $num[$y]?>">   
    <?php 
     } 
    ?> 
<!-- hidden inputs from first form(create.php) --> 
<br> 

    <fieldset style="background-color:white;"> 
     <legend style="font-size: 20px;">Add Stuff</legend> 
     <br><br><br> 
     <div class="small-3 large-3 columns"> 
     <label>Choose username</label> 
     <input placeholder="Search Me" id="box" type="text" /> 
     <div id="myAccordion"> 
     <?php for($i=321; $i<347; $i++) 
      { 
       echo "<h3>".chr($i)."</h3>"; 
       echo '<ul class="source">'; 
       $sql = "SELECT username FROM user WHERE username LIKE '".chr($i+32)."%' "; 
       $result = $conn->query($sql);  
       if ($result->num_rows > 0) 
       { 
        // output data of each row 
        while($row = $result->fetch_assoc()) 
        { 
         $name= $row["username"];  
         echo"<li>". $name ."</li>"; 
        } 
       } else 
       { 
        echo "0 results"; 
       }      
       echo '</ul>';     
      } 
     ?> 
     </div> 
     </div> 
     <div id="project" class="small-9 large-9 columns"> 
     <label style="font-size: 40px; margin-left:10%;">Project <?php echo isset($_POST['code'])?$_POST['code']:''; ?></label> 
     <div class="rowone"> 
      <div id="leader"> 
      <label>Leader:</label> 
       <div class="ui-widget-content"> 
       <div id="projLeader"> 
        <ol> 
         <li class="placeholder" name="leader" <?php if (isset($leader)) echo 'value="'.$leader.'"' ?>>Add leader here</li> 
         <input type="hidden" name="leader" id="hiddenListInput1" /> 
        </ol> 
       </div> 
       </div> 
      </div> 
      <div id="checker"> 
      <label>Checker:</label> 
       <div class="ui-widget-content"> 
       <div id="projChecker"> 
       <ol> 
        <li class="placeholder" name="checker" <?php if (isset($checker)) echo 'value="'.$checker.'"' ?>>Add checker here</li> 
        <input type="hidden" name="checker" id="hiddenListInput2" /> 
       </ol> 
       </div> 
       </div> 
      </div>     
      <div id="info"> 
      <label>Information:</label> 
       <div class="ui-widget-content"> 
       <ol> 
        <li>Total:</li> 
        <li>Total:</li> 
        <li>Total:</li> 
        <li>Total:</li> 
        <li>Total:</li> 
       </ol> 
       </div> 
      </div> 
     </div> 
     <div class="row"> 
      <input type = "submit" id="savebutton" style="margin-left:300px; width:150px;" name ="submit" class="button" value = "Create Project" onclick="userSubmitted = true;" /> 
     </div> 
     </div> 
    <div id="formModal" class="reveal-modal small" data-reveal aria-labelledby="modalTitle" aria-hidden="true" role="dialog" data-options="close_on_background_click:false"> 
     <h2 id="modalTitle">Success!</h2> 
     <div style="font-weight: 400;font-size: 1.5em; font-family: 'Raleway', Arial, sans-serif;">Your Accident Report was Successfully Submitted!</div> 
     <div class="right"> 
      <a href="#" id="closebtn" onclick="popUpNo()" class="button">Ok</a> 
     </div> 
    </div>   
     <?php  
      if($counta==1) 
      { 
       if($res=="") 
       { 
        $testing = JSON_encode($_SESSION['role']); 
        echo '<script>userSubmitted = true;</script>'; 
        insertRecord(); 
        echo "<script type ='text/javascript'>callShowAlert();</script>"; 
       } 
       else{ 
        echo " 
          <br><br><a style='color:red';> 
           $res 
          </a> 
         "; 
       } 
      } 
     ?>   
     <script>var testing = JSON.parse('<?= $testing; ?>');</script>   
    </fieldset> 
</form> 

这是我第二次提交表格后得到:

注意

未定义指数:处理在C:\ XAMPP \ htdocs中\项目\ 1ver \ create2.php 第9行

通知

未定义指数:numberpl在C:\ XAMPP \ htdocs中\项目\ 1ver \ create2.php 第12行

通知

未定义指数:代码在 C:\ XAMPP \ htdocs中\项目\ 1ver \ create2.php上线

通知

未定义指数:标题中 C:\ XAMPP \ htdocs中\项目\ 1ver \ create2.php上线

通知

未定义指数:标题在C:\ XAMPP \ htdoc小号\项目\ 1ver \ create2.php上 线302

我用另一个PHP页面将数据插入到数据库中。我只是不明白什么是问题。感谢您的帮助

+0

这段代码写在Create.php或create2.php?请分享这两个文件的代码。 –

+0

@AJ见编辑后 –

+0

感谢您的编辑。但是你没有提供完整的create2.php代码。不过,我想说你必须在回应一些事情之前先使用一个条件。我发布了一个答案,看看它是否有帮助。 –

回答

0

由于POST阵列不适用于第一次。因此,您正在收到此错误。如果你确实需要使用这些post变量,那么在这种情况下应该应用一个条件来避免这些错误。

我在这里添加一个,你可以为剩余的做同样的事情。

试试这个:

<?php echo isset($_POST['code'])?$_POST['code']:''; ?> 
+0

谢谢,我试过了,编辑我的代码,现在我得到另一个通知:注意:未初始化的字符串偏移量:0在C:\ xampp \ htdocs \第521行和第522行的Projects \ 1ver \ create2.php这是第521行和第522行:echo“Process:”。“$ proc [$ y]”。“”; echo“需要的人员:”。“$ num [$ y]”。“”; –

+0

是的,它不再出现 –

+0

我为每个变量做了'isset'。仍然出现此错误,您可以查看已编辑的帖子。 –