请分析一下我的代码哪里有问题?运行报错呢
运行后会导出一个xls表格,但是打开表格后里面是错误信息,实在不会排查错误,请大神帮忙看看Notice: Undefined variable: goods_name in D:\phpStudy\WWW\db.php on line 38
Notice: Undefined variable: gongjinjia in D:\phpStudy\WWW\db.php on line 39
Notice: Undefined variable: xinghao in D:\phpStudy\WWW\db.php on line 40
Notice: Undefined variable: caizhi in D:\phpStudy\WWW\db.php on line 41
<?php
error_reporting(E_ALL ^ E_DEPRECATED);
$localhost = '127.0.0.1';
$dbname = 'test';
$dbuser = 'root';
$dbpwd = 'root';
$tbname = "yz_info";
ob_end_clean();
header('Content-type: text/html; charset=utf-8');
header("Content-type:application/vnd.ms-excel;charset=UTF-8");
header("Content-Disposition:filename=data.xls");// 文件名自己改,默认data.xls
$conn = mysql_connect($localhost,$dbuser,$dbpwd) or die("连接数据库失败");
mysql_select_db($dbname, $conn);
mysql_query("set names 'UTF-8'");
$result=mysql_query("SELECT * FROM $tbname");
echo "<table>";
echo "<tr>";
echo "<th>A1单元格</th>";
echo "<th>B1单元格</th>";
echo "<th>C1单元格</th>";
echo "<th>D1单元格</th>";
echo "</tr>";
echo "</table>";
while($row=mysql_fetch_array($result)){
//下面data改成你自己数据库对应的字段
$data1 = $row["goods_name"];
$data2 = $row["gongjinjia"];
$data3 = $row["xinghao"];
$data4 = $row["caizhi"];
//输出字段的数据到单元格
//下面data改成你自己数据库对应的字段
echo "<table>";
echo "<tr>";
echo "<td>$goods_name</td>";
echo "<td>$gongjinjia</td>";
echo "<td>$xinghao</td>";
echo "<td>$caizhi</td>";
echo "</tr>";
echo "</table>";
}
?>