PHP 新手。试图简单地将 mySQL 表的内容输出到我的 HTML 页面上。这是我的html代码:
<body>
<div>
<?php
$hostname = "XXXXX";
$username = "XXXXX";
$password = "XXXXX";
$db_name = "XXXXX";
//connect to database
mysql_connect($hostname, $username, $password) or die("cannot connect to server");
mysql_select_db("$db_name") or die("cannot select database");
$sql="SELECT * FROM myTable";
$result=mysql_query($sql);
if (!$result) {die("SQL error retrieving data.");}
while ($row = mysql_fetch_array($result)) {
echo $row['field1'] . $row['field2'] . "</br>";
}
mysql_close();
?>
</div>
</body>
我的输出很简单:
"; } mysql_close(); ?>
我知道表中有数据。我看不出我做错了什么。任何人都可以帮忙吗?谢谢!