Iam嘗試顯示數據庫中的內容。 沒有值顯示。 爲什麼我的代碼不工作?我的xampp服務器也在運行!網頁不顯示數據庫內容
<html>
<body>
<?php$username="";$password="";$database="login";
mysql_connect("localhost:170",$username,$password);
@mysql_select_db($database) or die("Unable to select database");
$query="SELECT * FROM logindetails";
$result=mysql_query($query);
$num=mysql_numrows($result);mysql_close();?>
<table border="0" cellspacing="2" cellpadding="2">
<tr>
<td>
<font face="Arial, Helvetica, sans-serif">Value1</font>
</td>
<td>
<font face="Arial, Helvetica, sans-serif">Value2</font>
</td>
</tr>
<?php$i=0;while ($i < $num) {$f1=mysql_result($result,$i,"Username");
$f2=mysql_result($result,$i,"Email");?>
<tr>
<td>
<font face="Arial, Helvetica, sans-serif"><?php echo '$f1'; ?></font>
</td>
<td>
<font face="Arial, Helvetica, sans-serif"><?php echo '$f2'; ?></font>
</td>
</tr>
<?php$i++;}?>
</body>
</html>
'username =「」;'這意味着沒有用戶!你能連接到數據庫嗎?可能你應該使用'username =「root」;'。 –
爲什麼開始標籤和變量'<?php $ ...'之間沒有空格? – Sean
另外,當回聲 - >'<?php echo $ f1; ?>'而不是'<?php echo'$ f1'; ?> – Sean