2015-12-06 67 views
0

大家好,我試圖寫一個PHP代碼讀取從我的數據庫中的信息,遺憾的是我得到了以下錯誤消息:讀取數據形式MySQL表

注意:未定義指數:numcontrat在C:\ wamp \ www \ test \ crud-php-simple-master \ crud-php-simple-master \ index.php在第46行和 注意:未定義索引:在C:\ wamp \ www \ test \ crud-php-上線簡單的主\ CRUD-PHP-簡單的主\的index.php 51

我與你分享我的源代碼:

<?php` 

    //including the database connection file 
    include_once("config.php"); 

?> 

<html> 
    <head> 
     <title>Homepage</title> 
    </head> 

    <body> 
     <a href="add.html">Add New Data</a><br/><br/>  
     <table width='80%' border=0>  
      <tr bgcolor='#CCCCCC'>  
       <td style="background-color:#57D251; "> <b>&nbsp; N Contrat</b></td> 
       <td style="background-color:#57D251; " ><b>&nbsp;Avenant</b></td> 
       <td style="background-color:#57D251; " ><b>&nbsp;Discription</b></td> 
       <td style="background-color:#57D251; " ><b>&nbsp;Fournisseur</b></td> 
       <td style="background-color:#57D251; " ><b>&nbsp;Delai</b></td> 
       <td style="background-color:#57D251; " ><b>&nbsp;Date de notification</b></td> 
       <td style="background-color:#57D251; " ><b>&nbsp; Date envigyeur</b></td> 
       <td style="background-color:#57D251; " ><b>&nbsp;Date de fin caution</b></td> 
       <td style="background-color:#57D251; " ><b>&nbsp;Avance forfaitaire</b></td> 
      </tr> 
     <?php 
      //fetching data in descending order (lastest entry first) 
      $sql= 'SELECT * FROM contrats '; 
      $result = mysql_query($sql); 

      if (! $result){ 
       echo('Database error: ' . mysql_error()); 
      } 

      echo $result;  

      while($res = mysql_fetch_assoc ($result)) {   
       echo "<tr>"; 
       echo "<td>" .$res['numcontrat']."</td>" ; 
       echo "<td>" .$res['avenant']."</td>" ; 
       echo "<td>" .$res['discription']."</td>" ; 
       echo "<td>" .$res['fournisseur']."</td>" ; 
       echo "<td>" .$res['delai']."</td>" ; 
       echo "<td>" .$res['dnotification']."</td>" ; 
       echo "<td>" .$res['denvigyeur']."</td>" ; 
       echo "<td>" .$res['dcaution']."</td>" ; 
       echo"<td>" .$res['aforfaitaire']."</td>" ; 
       echo "<tr>"; 

       //echo "<td><a href=\"edit.php?id=$res[id]\">Edit</a> | <a href=\"delete.php?id=$res[id]\" onClick=\"return confirm('Are you sure you want to delete?')\">Delete</a></td>";  
      }   
     ?> 
     </table> 
    </body> 
</html> 

感謝您的回答

+1

這些數組中的字段必須在對照表 –

+0

問題仍然存在,我也有同樣的錯誤:未定義的索引:numcontrat在C:\ wamp \ www \ test \ crud-php-simple-master \ crud-php- simple-master \ index.php第46行 –

+0

你可以發送你的表結構嗎? –

回答

1

根據你的例外,dnotification列不會在你的餐桌contrats存在。

在您的數據庫表中創建此列,然後嘗試。

在您的評論你提到

//降序排列(最新的入門第一)

$ sql中獲取數據= 'SELECT * FROM contrats';

但它會在它按降序排列stored.To獲取訂單獲取,使用查詢這樣的事情...

​​

其中id是自動增量場。