2014-09-13 232 views
0

好吧,所以我在代碼中添加了一條if語句給我的while()。修正了一些錯誤,yadayada。現在我收到文件意外結束的錯誤。我沒有關閉一些東西嗎?因爲我現在一直在尋找錯誤。 (是的,我知道。並不是每一個單詞是英語。他們大多是名字,雖然)。文件意外結束?

<?php 

include 'inc.php'; 

$sql = mysqli_query($mysql, " 
    SELECT a.ArtID, a.Productnaam, a.Inkoopprijs, a.LevID, v.Voorraad, v.Min_voorraad 
    FROM artikelen a, voorraad v 
    WHERE a.ArtID = v.ArtID 
    ORDER BY a.Productnaam"); 

if($sql === FALSE){ 
    die(mysqli_error()); 
} 

?> 

<nav> 
    <div id="menubar"> 
     <ul id="nav"> 
      <li><a href="index.php">Home</a></li> 
      <li><a href="login.php">Login</a></li> 
      <li class="current"><a href="artikelenOve.php">Artikelen</a></li> 
     </ul> 
    </div> 
</nav> 
<div id="site_content">  
    <div id="content"> 
     <div class="content_item"> 
      <form action="artikelenOve.php" method="post"> 
       <input type="submit" name="add" value="Voeg een artikel toe"><br><br> 
       <table border="1"><tr><td>ID</td> 
       <td>Naam</td> 
       <td>Inkoopprijs</td> 
       <td>Leverancier ID</td> 
       <td>Voorraad</td> 
       <td>Minimum</td> 
       <td>Wijzigen</td> 
       <td>Verwijderen</td></tr> 

       <?php 

       $result = $rArt['Voorraad'] - $rArt['Min_voorraad']; 

       while($rArt = mysqli_fetch_array($sql)){ 
        echo '<tr><td>' . $rArt['ArtID'] . '</td>'; 
        echo '<td>' . $rArt['Productnaam'] . '</td>'; 
        echo '<td>' . $rArt['Inkoopprijs'] . '</td>'; 
        echo '<td>' . $rArt['LevID'] . '</td>'; 
        echo '<td>' . $rArt['Voorraad'] . '</td>'; 
        echo '<td>' . $rArt['Min_voorraad'] . '</td>'; 
        if($result < 0){ 
         echo '<td bgcolor="red"></td>'; 
        }elseif($result >= $rArt['Min_voorraad'] && $result <= $rArt['Min_voorraad'] * 1.2){ 
         echo '<td bgcolor="yellow"></td>'; 
        }else{ 
         echo '<td bgcolor="green"></td>'; 
        } 
        echo '<td><input type="submit" name="edit" value="Wijzig"></td>'; 
        echo '<td><input type="submit" name="delete" value="Verwijder"></td></tr>'; 
       } 

       if(isset($_POST['add'])){ 
        header('Location: artikelenToe.php'); 
       } 

       if(isset($_POST['edit'])){ 
        header('Location: artikelenWij.php'); 
       } 

       if(isset($_POST['delete'])){ 
        $sql2 = mysqli_query($mysql, " 
         DELETE FROM voorraad v 
         WHERE v.ArtID = " . $_GET['delete'] . ""); 

        $sql3 = mysqli_query($mysql, " 
         DELETE FROM artikelen a 
         WHERE a.ArtID = " . $_GET['delete'] . ""); 
       ?> 

      </form></table> 
     </div> 
    </div> 
</div>  
</div> 
<script type="text/javascript" src="js/jquery.js"></script> 
</body> 
</html> 
+1

拿起任何像樣的IDE輕鬆檢測到這種錯誤。如果你每次來這裏尋求幫助,你都會浪費很多時間。 – Sugar 2014-09-13 17:52:09

+0

到目前爲止,我第一次在我的4年編碼中遇到過這種情況。當然,這是我犯的一個愚蠢的錯誤(正如答案所述,我留下了一個開放的答案),但是使用程序糾正這些錯誤並不會幫助我學會停止犯這些錯誤。 – BigbyBoss72 2014-09-13 17:57:12

+0

您的代碼易受SQL注入影響。你應該閱讀[如何在PHP中防止它們](http://stackoverflow.com/q/60174/53114)。 – Gumbo 2014-09-13 17:59:04

回答

1

你一直線70 if(isset($_POST['delete'])){一個開放的大括號這是從來沒有關閉。

更正代碼:

<?php 

include 'inc.php'; 

$sql = mysqli_query($mysql, " 
    SELECT a.ArtID, a.Productnaam, a.Inkoopprijs, a.LevID, v.Voorraad, v.Min_voorraad 
    FROM artikelen a, voorraad v 
    WHERE a.ArtID = v.ArtID 
    ORDER BY a.Productnaam"); 

if($sql === FALSE){ 
    die(mysqli_error()); 
} 

?> 

<nav> 
    <div id="menubar"> 
     <ul id="nav"> 
      <li><a href="index.php">Home</a></li> 
      <li><a href="login.php">Login</a></li> 
      <li class="current"><a href="artikelenOve.php">Artikelen</a></li> 
     </ul> 
    </div> 
</nav> 
<div id="site_content">  
    <div id="content"> 
     <div class="content_item"> 
      <form action="artikelenOve.php" method="post"> 
       <input type="submit" name="add" value="Voeg een artikel toe"><br><br> 
       <table border="1"><tr><td>ID</td> 
       <td>Naam</td> 
       <td>Inkoopprijs</td> 
       <td>Leverancier ID</td> 
       <td>Voorraad</td> 
       <td>Minimum</td> 
       <td>Wijzigen</td> 
       <td>Verwijderen</td></tr> 

       <?php 

       $result = $rArt['Voorraad'] - $rArt['Min_voorraad']; 

       while($rArt = mysqli_fetch_array($sql)){ 
        echo '<tr><td>' . $rArt['ArtID'] . '</td>'; 
        echo '<td>' . $rArt['Productnaam'] . '</td>'; 
        echo '<td>' . $rArt['Inkoopprijs'] . '</td>'; 
        echo '<td>' . $rArt['LevID'] . '</td>'; 
        echo '<td>' . $rArt['Voorraad'] . '</td>'; 
        echo '<td>' . $rArt['Min_voorraad'] . '</td>'; 
        if($result < 0){ 
         echo '<td bgcolor="red"></td>'; 
        }elseif($result >= $rArt['Min_voorraad'] && $result <= $rArt['Min_voorraad'] * 1.2){ 
         echo '<td bgcolor="yellow"></td>'; 
        }else{ 
         echo '<td bgcolor="green"></td>'; 
        } 
        echo '<td><input type="submit" name="edit" value="Wijzig"></td>'; 
        echo '<td><input type="submit" name="delete" value="Verwijder"></td></tr>'; 
       } 

       if(isset($_POST['add'])){ 
        header('Location: artikelenToe.php'); 
       } 

       if(isset($_POST['edit'])){ 
        header('Location: artikelenWij.php'); 
       } 

       if(isset($_POST['delete'])){ 
        $sql2 = mysqli_query($mysql, " 
         DELETE FROM voorraad v 
         WHERE v.ArtID = " . $_GET['delete'] . ""); 

        $sql3 = mysqli_query($mysql, " 
         DELETE FROM artikelen a 
         WHERE a.ArtID = " . $_GET['delete'] . ""); 
       } 
       ?> 

      </form></table> 
     </div> 
    </div> 
</div>  
</div> 
<script type="text/javascript" src="js/jquery.js"></script> 
</body> 
</html> 
+0

非常感謝!通常是這些愚蠢的小錯誤,但通常我可以找到它們。 – BigbyBoss72 2014-09-13 17:57:46

1
This is a parse error which occurs when php is still looking for something and reaches the end of the file without finding it. It could be a quote or bracket which is unclosed, and php is still treating the file contents as a part of the quote. 

您havnt封閉的if(isset($_POST['delete'])){

添加結束括號將解決問題的支架..

if(isset($_POST['delete'])){ 
       $sql2 = mysqli_query($mysql, " 
        DELETE FROM voorraad v 
        WHERE v.ArtID = " . $_GET['delete'] . ""); 

       $sql3 = mysqli_query($mysql, " 
        DELETE FROM artikelen a 
        WHERE a.ArtID = " . $_GET['delete'] . ""); 
      }