html中的博客条目未能由php处理

时间:2018-03-01 17:51:11

标签: php html

所以我有主要的博客页面“viewBlog.php”,以及一个可以添加条目“add_entry.html”的页面。 add_entry中提交的信息应该显示在viewBlog中,但事实并非如此,因为它只是保持空白。我不知道为什么add_entry中提交的信息没有被处理并在viewBlog的主div上回显。

add_entry.html代码:

<html xmlns = "http://www.w3.org/1999/xhtml">
<head> <title> Add Entry </title>
</head>
<body style="background-color:antiquewhite;">
<h1 style="color:red; font-family:arial"> Add an entry to Blog! </h1>
  <p>
    Instructions: Enter a title and body for your blog entry. In the body, you can use simple HTML formatting elements, such as &#60b&#62 (bold) and &#60i&#62 (italic) as well as the hyperlink "anchor" element &#60a&#62.
  </p>
<form action="viewBlog.php" method="POST">
  <table>
    <tr>
      <td>
        Title:
      </td>
      <td>
        <input type="text" name="title" size="61" maxlength="60">
      </td>
    </tr>
    <tr>
      <td valign="top">
        Body:
      </td>
      <td>
        <textarea name="body" rows="10" cols="80"></textarea>
      </td>
    </tr>
    <tr>
      <td>
      </td>
      <td>
        <input type="Submit" value="Add Entry" name="">
        <input type="reset" onClick="return confirm('Clear the form?');" value="Clear" name="">
      </td>
    </tr>
  </table>
</form>

viewBlog.php代码:

<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <title>Homepage</title>
    <link rel="stylesheet" type="text/css" href="miniCSS.css" title="Style 1" />
</head>
<body>

<div id="wrap">

<div id="header">
<img src="banner.png" alt="banner" height="150px"/>
</div>

<div id="main">
<?php

$title = $_POST["title"];
$body = $_POST["body"];

echo "$title";
echo "$body";

?>
</div>

<div id="sidebar">
  <ul>
    <li><a href="viewBlog.php">Home</a></li>
    <li><a href="add_entry.html">Add Entry</a></li>
  </ul>
</div>

<div id="footer">

</div>

</div>

</body>
</html>

1 个答案:

答案 0 :(得分:0)

当你回显变量时,不要在它们周围加上引号,将它们转换为字符串(字面意思为$title$body)。所以不是这个

echo "$title";
echo "$body";

这样写:

echo $title;
echo $body;