2017-07-22 31 views
-2

投稿ボタンを押すと、コメントがページに投稿されています。私がもう一度ヒットしたら、前のコメントよりも優先されます。誰かがこれを明らかにすることができますか?そして、私は日付を表示するJavaスクリプトを実行しています。コメントなしでも常時表示されています。どうすればそれも変更できますか? ありがとうございます!コメント欄のコメントは無効になっています投稿していません

<h3 id="reply-title" class="comment-reply-title">Leave a Reply </h3> 
 

 
<form action="" method="post"> 
 

 
<p class="comment-notes"><span id="email-notes">Your email address will not be published.</span> Required fields are marked <span class="required">*</span></p> 
 
<p class="comment-form-comment"><label for="comment">Comment</label> <textarea id="comment" name="comment" cols="45" rows="8" maxlength="65525" aria-required="true" required="required"></textarea></p> 
 

 
<p class="comment-form-author"><label for="author">Name <span class="required">*</span></label> <input id="author" name="author" type="text" value="" size="30" maxlength="245" aria-required="true" required="required"></p> 
 

 
<p class="comment-form-email"><label for="email">Email <span class="required">*</span></label> <input id="email" name="email" type="email" value="" size="30" maxlength="100" aria-describedby="email-notes" aria-required="true" required="required"></p> 
 

 
<p class="form-submit"><input name="submit" type="submit" id="submit" class="submit" value="Post Comment"></p> 
 
<div> 
 
    <?php 
 
     if($_POST) { 
 
      $name = $_POST['author']; 
 
      $comment = $_POST['comment']; 
 
      $email = $_POST['email']; 
 
     #echo $name . $comment . $email; 
 
      $handle = fopen("comments/get-more-twitter-followers.html", "a"); 
 

 
      fwrite($handle, "\n".$name."\n".$comment."\n". $email. "\n"); 
 
      fclose($handle); 
 

 
     } 
 
    ?> 
 
    <?php 
 
     if($_POST) { 
 
      $email = $_POST['email']; 
 
      $useremail = fopen("useremail.html", "a"); 
 
      fwrite($useremail, "\n".$email. "\n"); 
 
      fclose($useremail); 
 

 
     } 
 
    ?> 
 
</div> 
 
<div> 
 
    <div> 
 
     <p><strong><h4><u>Comments:</u></h4></strong></p> 
 
    </div> 
 
    <div> 
 
     <div> 
 
      <strong><?php 
 
       $name = $_POST['author']; 
 
       echo $name; ?> </strong> <small><script type="text/javascript"> 
 
               var d = new Date() 
 
               document.write(d.getDate()) 
 
               document.write("/") 
 
               document.write(d.getMonth() + 1) 
 
               document.write("/") 
 
               document.write(d.getFullYear()) 
 
               </script> 
 
          </small> 
 
     </div> 
 
     <div> 
 
      <p> 
 
       <?php 
 
        $comment = $_POST['comment']; 
 
        echo "\n".$comment."\n"."<hr>"; 
 
       ?> 
 
      </p> 
 
     </div> 
 
    </div> 
 
</div>

+0

とAjaxのポストにURLを変更することを忘れないでください、私は、何かを理解していないあなたは、DBファイルにコメントを保存し、されていませんか? – Treast

+0

あなたはファイルに書き込みますが、あなたはそれを読むことはありません。代わりに最新のコメントを書いています。 –

+0

あなたのフォームはどこですか? –

答えて

0

あなたのアプローチは間違った使用は、コメントデータを保存し、データベースからデータをretriveするためにPHPを使用するデータベースです。

コード化したくない場合は、コメントシステムが必要なプロジェクトでの統合が非常に簡単なdisqusを使用してください。

+0

私は同意します。ファイルへの書き込みは、スレッド保護なしで複数のユーザーを処理することはありません。 –

0

ホワイイとはどういう意味ですか? 'あなたのメールアドレスが公開されることはありません。'大声で叫ぶために、すべての「メールアドレス」を平文ファイルに書きます。このオンラインは作成しないでください。

PHPで
<div> 
    <strong><?php 
    $name = $_POST['author']; 
    echo $name; ?> </strong> <small><script type="text/javascript"> 
    var d = new Date() 
    document.write(d.getDate()) 
    document.write("/") 
    document.write(d.getMonth() + 1) 
    document.write("/") 
    document.write(d.getFullYear()) 
</script> 
</small> 
</div> 
<div> 
<p><?php 
$comment = $_POST['comment']; 
echo "\n".$comment."\n"."<hr>"; 
?></p></div> 
</div></div> 
</div> 

$_POSTは、スクリプトがあるPOSTリクエストのボディを指し:あなたはコメントをペイントするために戻ってファイルを読んでいない

0

、あなただけに来たPOSTデータを使用していますへの対応。

  1. をファイルから読み込み:

    は、次の3つのことを行い機能を備えたものを交換する必要があります。

  2. authorcommentを使用してレコードを異なるエントリに分割します。
  3. これらのエントリを繰り返し、レコードごとに別のdivをペイントします。

もう1つの問題点:あなたのコードは現在の日付をコメントの日付として表示しています。コメントの日付を保存していない場合は、日付を表示しないでください。

-1
<?php 
$comment = $_POST['comment']; 
$name = $_POST['author']; 
$data_post->name = $name; 
$data_post->comment = $comment; 

if(isset($name, $comment)){ 
    header('Content-type: application/json'); 
    echo(json_encode($data_post)); 
    return; 
} 
?> 
<html> 
    <head> 
     <script 
      src="https://code.jquery.com/jquery-1.12.4.min.js" 
      integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=" 
      crossorigin="anonymous"></script> 
     <script> 
      $("document").ready(function(){ 
       $("#comment").on("submit", function(e){ 
        var comment = $('#comment'); 
        e.preventDefault(); 
        $.ajax({ 
         method: "POST", 
         url: "index.php", // your php file name 
         data: comment.serialize(), 
         success: function (data) { 
          var d = new Date(); 
          var data_comment = "<div><small>"+d.getDate()+"/"+(d.getMonth() + 1)+"/"+d.getFullYear()+"</small></div><strong>"+data.name+"</strong><p>"+data.comment+"</p>" 
          $("#list_comment").append(data_comment); 
          comment[0].reset(); 
          console.log(data.name); 
         }, 
         error: function (data) { 

         }, 
        }) 
       }); 
      }); 
     </script> 
    </head> 
    <body> 
     <h3 id="reply-title" class="comment-reply-title">Leave a Reply </h3> 
     <form action="" method="post" id="comment"> 
      <p class="comment-notes"><span id="email-notes">Your email address will not be published.</span> Required fields are marked <span class="required">*</span></p> 
      <p class="comment-form-comment"><label for="comment">Comment</label> <textarea id="comment" name="comment" cols="45" rows="8" maxlength="65525" aria-required="true" required="required"></textarea></p> 
      <p class="comment-form-author"><label for="author">Name <span class="required">*</span></label> <input id="author" name="author" type="text" value="" size="30" maxlength="245" aria-required="true" required="required"></p> 
      <p class="comment-form-email"><label for="email">Email <span class="required">*</span></label> <input id="email" name="email" type="email" value="" size="30" maxlength="100" aria-describedby="email-notes" aria-required="true" required="required"></p> 
      <p class="form-submit"><input name="submit" type="submit" id="submit" class="submit" value="Post Comment"></p> 
     </form> 
     <div> 
      <div> 
       <p><strong><h4><u>Comments:</u></h4></strong></p> 
      </div> 
      <div id="list_comment"> 

      <div> 
     </div> 
    </body> 
</html> 

は、PHPのファイル名(ライン26)

関連する問題