duanduan8439 2015-03-24 21:21
浏览 35
已采纳

PHP包括不在新的LAMP服务器上工作

I am working on converting an application I wrote in .NET over to a LAMP server.

I built a very basic PHP file that connects to a MySQL database and creates a drop-down list of usernames. This works fine by itself, and by executing it from the command line using "PHP -f file.php":

<?php
mysql_connect('localhost', 'user', 'password');
mysql_select_db("database");

$sql = "SELECT Username,Guid FROM Usernames";
$result = mysql_query($sql);

echo "<td><select name='users'>";

while($row = mysql_fetch_assoc($result)){
echo "<option value='" . $row['Guid'] . "'>" . $row['Username'] . "  </option>";
}   

echo "</select></td></tr> ";
?>

HOWEVER, when I try to include this file in an html file, it simply does not display, and I am not getting any errors. Here is the source from the basic HTML file:

<HTML>
<H1>This is my homepage</H1>
<?php 
error_reporting(E_ALL ^ E_NOTICE);
include 'ShowData.php';?>
</HTML>

My question is this: does apache2 natively allow for php include? In my case, both files are in the same directory "/var/www/html/". Or am I missing some base configuration somewhere to allow this? My LAMP server is a brand new install of Ubuntu 14LTS. LAMP was installed using the published "apt-get" commands.

  • 写回答

1条回答 默认 最新

  • duanmi4379 2015-03-24 21:31
    关注

    You can't run php in a .html file change the extension to .php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因