PHP + HTML错误;显示PHP代码,而不是处理它

PHP + HTML错误;显示PHP代码,而不是处理它

问题描述:

例如,测试代码: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

您需要通过Web服务器访问文件,而不是直接访问您的磁盘。

尝试:

http://localhost/pp-homecheck/DailyLog/dailylog_new.php

你不能直接从磁盘中打开HTML文件,并希望你的浏览器来解释所有的PHP脚本。

您需要实际安装一个像apache with php interpreter这样的网络服务器,并将浏览器指向本地apache安装文件根目录的url。