2012-03-08 83 views
0

例如,測試代碼:PHP + HTML錯誤;顯示PHP代碼,而不是處理它

<HTML> 
<BODY> 
<?php 
$connect = mysql_connect("localhost", "root", "password") or 
die ("Hey loser, check your server connection."); 
mysql_select_db("school"); 
$quey1="select * from student"; 
$result=mysql_query($quey1) or die(mysql_error()); 
?> 
<table border=1 style="background-color:#F0F8FF;" > 
<caption><EM>Student Record</EM></caption> 
<tr> 
<th>Student ID</th> 
<th>Student Name</th> 
<th>Class</th> 
</tr> 
<?php 
while($row=mysql_fetch_array($result)){ 
echo "</td><td>"; 
echo $row['stud_id']; 
echo "</td><td>"; 
echo $row['stud_name']; 
echo "</td><td>"; 
echo $row['stud_class']; 
echo "</td></tr>"; 
} 
echo "</table>"; 
?> 
</BODY> 
</HTML> 

給我: PHP Error

我也經歷了錯誤,使用不工作,而世界你好「;?>在html頁面將顯示'hello world';?>'在頁面上。 不知道什麼是錯的......任何人都有線索?

+0

答案指出你試圖直接調用腳本。您必須通過網絡服務器訪問它。最新的PHP有一個內置的網絡服務器。 http://php.net/manual/en/features.commandline.webserver.php – Martin 2012-03-08 03:36:23

+0

爲什麼哦爲什麼開發者會把它放在?猜測它可能對初學者有幫助。 – Corbin 2012-03-08 03:39:19

回答

1

你不能直接從磁盤中打開HTML文件,並希望你的瀏覽器來解釋所有的PHP腳本。

您需要實際安裝一個像apache with php interpreter這樣的網絡服務器,並將瀏覽器指向本地apache安裝文件根目錄的url。