2017-11-22 33 views
0

나는 각 행에 테이블과 두 개의 라디오 버튼을 만드는 html 코드가 있습니다. 루프와 나는 ++ 방식으로 사용하면서 각 열의 라디오 버튼에 다른 이름을 붙이기 위해.해결 방법 정의되지 않은 오프셋 : PHP에서 오류

<form action = "submit_varification.php" method = "POST" onclick = "return validate()"> 

         <div style="position: absolute; left: 50px; top: 90px;"> 
         <label class="right"><font color="white">Date:</font></label> 
         <input type="text" id = "frmDate" /><br> 
         <p id="date"></p> 
         </div> 
         <div style="position: absolute; left: 250px; top: 91px;"> 
         <label class="right"><font color="white">V-ID:</font></label> 
         <input type="text" id = "myText" name = "reviewer" value = ""/><br> 
         </div> 
         <div style="position: absolute; left: 900px; top: 91px;"> 
         <button type="button" name="show" id="show" onclick = "" >History</button> 
         </div> 
         <div style="position: absolute; left: 900px;"> 
         <input type="submit" name="test" id="test" value="Submit" /><br/> 
         </div> 

        <script> 
        var date = new Date(); 

        document.getElementById("frmDate").value = (date.getMonth() + 1) + '/' + date.getDate() + '/' + date.getFullYear(); 

        </script> 
       </body> 
       <table style="position: absolute; width:95%; left: 20px; top: 150px;" id = "table1"> 
        <?php 
        $myDate = date('m/d/Y'); 
        ?> 
         <tr> 
         <th>Date</th> 
         <th>Time</th> 
         <th>Alias</th> 
         <th>Machine_Name</th> 
         <th>Build_Name</th> 
         <th>Build_version</th> 
         <th>WinDBG</th> 
         <th>.Net_Framework</th> 
         <th>Status</th> 
         </tr> 
         <?php 
          //get records from database 
          $sql3 = "SELECT * FROM data WHERE `Date` = '".$myDate."' ORDER BY id DESC"; 
          $query = $conn->query($sql3); 
          if($query->num_rows > 0){ 
          $i = 0 ; 
          while($row = $query->fetch_assoc()){ ?> 
          <tr> 
          <td><?php echo $row['Date']; ?></td> 
          <td><?php echo $row['Time']; ?></td> 
          <td><?php echo $row['Alias']; ?></td> 
          <td><?php echo $row['Machine_Name']; ?></td> 
          <td><?php echo $row['Build_Name']; ?></td> 
          <td><?php echo $row['Build_Version']; ?></td> 
          <td><?php echo $row['WinDBG']; ?></td> 
          <td><?php echo $row['.NET_Framework']; ?></td> 
          <td style='white-space: nowrap'><form><label class = "ready"><input type="radio" name="[<?php $i ?>]" value = "Ready">Ready</label><label class = "notready"><input type="radio" name="[<?php $i ?>]" value = "Not Ready" >Not Ready</label></form></td> 
          </tr> 

          <?php $i++ ; } } ?> 


         </table> 


         </form> 

입니다 와 나는 데이터베이스에 각 행의 값을 저장합니다. 그래서 폼에 POST 메서드를 사용했습니다. 나는 데이터베이스에 라디오 버튼의 값을하려고하지만

Notice: Undefined offset: 0 in C:\wamp64\www\submit_varification.php on line 33 
Notice: Undefined offset: 1 in C:\wamp64\www\submit_varification.php on line 33 
Notice: Undefined offset: 2 in C:\wamp64\www\submit_varification.php on line 33 

같은 오류와 PHP 코드에 직면하고있다 :

$query = $conn->query($sql4); 
         if($query->num_rows > 0){ 
         $i = 0 ;  
         while($row = $query->fetch_assoc()){ 


          //...insert into your DB. 
         $row1 = $row["Date"]; 
         $row2 = $row["Time"]; 
         $row3 = $row["Alias"]; 
         $row4 = $row["Machine_Name"]; 
         $row5 = $row["Build_Name"]; 
         $row6 = $row['Build_Version']; 
         $row7 = $row["WinDBG"]; 
         $row8 = $row[".NET_Framework"]; 

         $status = $_POST["$i"]; // this is the error 


         $sql5 = "INSERT INTO history (`Date`, `Time`, `Alias`, `Machine_Name`, `Build_Name`, `Build_version`, `WinDBG`, `.NET_Framework`, `Status`, `Reviewed_By`) 
         VALUES ('".$row1."','".$row2."','".$row3."','".$row4."','".$row5."','".$row6."','".$row7."','".$row8."', '".$status."', '".$reviewer."') "; 
         if ($conn->query($sql5) === TRUE) { 
         //echo "New record created successfully"; 
         //echo nl2br("\n"); 
         echo ""; 

         } else { 
         echo "Error: " . $sql5 . "<br>" . $conn->error; 
         } 

         $i++ ; 
         } 
         } 

사람이 이것에 대한 어떤 해결책이된다?

+0

더 많은 HTML을 제공 할 수 있습니까? – Cashbee

+0

예 확실한 .......... –

+0

하지만 어떻게 ...............? –

답변

0

각 루프마다 $ i를 채우는 배열을 덤프합니다. 나는 배열에 name="[<?php $i ?>]"이 기대하는 배열 키가 없다는 것을 내기 할 것이다.

0

name 속성에서 대괄호를 제거하고 올바르게 작동하는지 확인할 수 있습니까? 아래는 코드입니다 : 당신이 할 수있는

<td style='white-space: nowrap'> 
<form><label class = "ready"> 
    <input type="radio" name="<?php $i ?>" value = "Ready">Ready</label> 
    <label class = "notready"><input type="radio" name="<?php $i ?>" value = "Not Ready" >Not Ready</label> 
</form> 

플러스 일부 정적 텍스트가 이름 열 및 서버 측에 추가 된 경우 더 나은 것, 루프는 :

<td style='white-space: nowrap'> 
<form><label class = "ready"> 
    <input type="radio" name="status_<?php $i ?>" value = "Ready">Ready</label> 
    <label class = "notready"><input type="radio" name="status_<?php $i ?>" value = "Not Ready" >Not Ready</label> 
</form> 

도와 주시면 알려주세요 ..

+0

나는 당신을 시험해 본다. 아이디어와 나는이 같은 PHP 코드 라인을 변경 : –

+0

$ status = $ _POST [ "status _"] [$ i]; –

+0

하지만 하나의 행에 하나의 후자처럼 데이터를 데이터베이스에 씁니다. –

0

중첩 된 양식을 작성합니다.

<td style='white-space: nowrap'><label class = "ready"><input type="radio" name="<?php $i ?>" value = "Ready">Ready</label><label class = "notready"><input type="radio" name="<?php $i ?>" value = "Not Ready" >Not Ready</label></td> 

는 또한 언급 GOPAL의 panadi처럼 괄호를 제거 : 라인이와

<td style='white-space: nowrap'><form><label class = "ready"><input type="radio" name="[<?php $i ?>]" value = "Ready">Ready</label><label class = "notready"><input type="radio" name="[<?php $i ?>]" value = "Not Ready" >Not Ready</label></form></td> 

를 교체합니다.
또한 안에 레이블을 입력 할 수 있는지 잘 모르겠습니다. 그들은 서로 옆에 있으면 안된다?

편집 : 그 후에 오류가 발생하면 $ _POST 배열을 덤프하고 라디오 값이 $ _POST에 있는지 확인하십시오. var_dump($_POST);die();