【发布时间】:2015-06-17 10:53:52
【问题描述】:
我一直在关注php教程here
代码
这是我的 html 文件:
<!DOCTYPE html>
<html>
<head>
<link rel=”stylesheet” type=”text/css” href=”style.css”>
<form action="postForm.php" method="post">
<TextArea name="microBlog" id="microBlog" cols="30" rows=“10"></TextArea>
<input type="submit">
</form>
</head>
<body>
<?php
require_once 'meekrodb.2.3.class.php';
DB::$user = 'root';
DB::$password = '';
DB::$dbName = 'MicroBlog';
$results = DB::query("SELECT post FROM MicroBlog");
foreach ($results as $row){
echo "<div class='microBlog'>" . $row['post'] . "</div>";
}
?>
</body>
</html>
这会产生以下结果:
但是,如果我将 php 代码复制到一个新的 postForm.php 文件中并单击“提交”(您可以看到操作是 postForm.php),它就可以工作。
我的空白屏幕显示 3 个单词(来自数据库)。
问题是它是一个全新的空白页,我不希望这样。
问题
为什么代码在 html 文件外有效,而在 html 文件内无效。为什么我在 html 文件中得到".row['post']."";} ?> 但当 php 存在于它自己的 php 文件中时我得到完美的输出?
代码显然没有错,那会是什么?
这真的让我很困惑。感谢您的任何回答。
【问题讨论】:
-
你的文件扩展名是什么?
-
这是一个 .html 文件。当我设置一个操作以使用相同的 php 代码打开一个单独的 .php 文件时,它突然起作用了。但是代码是一样的!
标签: php html mysql wamp meekro