注意:未定义的变量

时间:2013-08-27 03:06:48

标签: php error-handling

我遇到此警告的问题

注意:未定义的变量:第35行的C:\ wamp \ www \ android_connect \ cara1.php中的T_Person

警告:第35行的C:\ wamp \ www \ android_connect \ cara1.php中为foreach()提供的参数无效

第35行是foreach($ T_Person为$ Person)

我不明白哪里出错了 这是我的PHP代码:

<!DOCTYPE html>
<html>
<head>
<title>Daftar Buku</title>
<!--Bagian CSS untuk Styling Tabel-->
<style type="text/css">
      table, th, td
      {
           border: 1px solid black;
      }
</style>
</head>
<body>

<h3>Daftar Buku Terbaru</h3>
<?php

$Person = new SimpleXMLElement('contoh.xml', null, true);


echo "
<table>
<tr>
<th>First name</th>
<th>middle name</th>
<th>Alias</th>
<th>Gender</th>
<th>City</th>
<th>Person ID</th>
</tr>

";

 foreach($T_Person as $Person)
 {
    echo "
 <tr>
 <td width='200'>{$Person->First_name}</td>
 <td width='200'>{$Person->Middle_Name_Person}</td>
 <td width='130'>{$Person->Alias_Person}</td>
 <td width='80'>\${$Person->Gender_Person}</td>
 <td width='130'>{$Person->CityBirth_Person}</td>
 <td width='130'>{$Person['Person ID']}</td>
 </tr>

 ";
 }
 echo '</table>';
 ?>

</body>
</html>

1 个答案:

答案 0 :(得分:5)

因为$T_Person未设置或不是数组。我相信你的意思是这样做

$T_Person = new SimpleXMLElement('contoh.xml', null, true);
相关问题