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> N Contrat</b></td>
<td style="background-color:#57D251; " ><b> Avenant</b></td>
<td style="background-color:#57D251; " ><b> Discription</b></td>
<td style="background-color:#57D251; " ><b> Fournisseur</b></td>
<td style="background-color:#57D251; " ><b> Delai</b></td>
<td style="background-color:#57D251; " ><b> Date de notification</b></td>
<td style="background-color:#57D251; " ><b> Date envigyeur</b></td>
<td style="background-color:#57D251; " ><b> Date de fin caution</b></td>
<td style="background-color:#57D251; " ><b> 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>
感謝您的回答
這些數組中的字段必須在對照表 –
問題仍然存在,我也有同樣的錯誤:未定義的索引:numcontrat在C:\ wamp \ www \ test \ crud-php-simple-master \ crud-php- simple-master \ index.php第46行 –
你可以發送你的表結構嗎? –