评论系统无法通过php

时间:2016-12-20 07:16:23

标签: php html css

我在互联网上看到的留言簿类型情况的评论发布教程对许多其他人来说都很好,但对我来说,我一直有

" . $name. ":
" . $content . "
"); fclose ($handle); } ?> 

出现在评论框上方。在php中完成所有操作后,它也不会发布任何内容。这是代码:

<?php

if($_POST){
    $name = $_POST ['name'];
    $content = $_POST ['commentcontent'];
    $handle = fopen("JackPackNetwork.html","a");
    fwrite ($handle, "<b>" . $name. "</b>:<br/>" . $content  .  "<br/>");
    fclose ($handle);
}
?>

<html>
<head>
</head>
<body>
<form action="" method= "POST">

Comments: <textarea rows= "10" cols= "30" name= "commentContent"></textarea> <br/>
Name: <input type= "text" name = "name"> <br/>
<input type= "submit" value = "Post!"> <br/>
</form>
<?php include "JackPackNetwork.html"; ?>
</body>
</html>

具体来说,我想链接到JackPackNetwork.html并更新评论,并且能够让某人能够在其上添加他们的名字。感谢您的时间和考虑。

1 个答案:

答案 0 :(得分:0)

您的代码应如下所示:

<?php

if($_POST){
$name = $_POST ['name'];
$content = $_POST ['commentContent'];
$handle = fopen("JackPackNetwork.html","a");
fwrite ($handle, "<b>" . $name. "</b>:<br/>" . $content  .  "<br/>");
fclose ($handle);



}

?>


<html>
<head>
</head>
<body>
<form action="" method= "POST">

Comments: <textarea rows= "10" cols= "30" name= "commentContent"></textarea>      <br/>
Name: <input type= "text" name = "name"> <br/>
<input type= "submit" value = "Post!"> <br/>
</form>
<?php require_once("JackPackNetwork.html"); ?>
</body>
</html>

<强> MISTAKE

  1. 数组索引区分大小写,因此$ content post post fetch应该正确完成。
  2. <强>建议

    1. 使用require_once()而不是include()。