2016-09-22 167 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'。仍然出現此錯誤,您可以查看已編輯的帖子。 –