2016-05-09 4 views
-1

MySQLのコメントテーブルに格納されている情報を入力に表示しようとしていますが、問題があります。 enterCommentという名前の入力は私のDBにデータを挿入し、それはshowComment入力にリダイレクトされます。データベースのレコードを表示する

HTML:

form action='takedata.php' method='POST'> 
      <input type='text' id='enterComment' name='enterComment' width='400px' placeholder='Write a comment...'> 
      <input type='submit' id='combuton' name='comButon' value='Comment!'> 
      <input type='text' id='showComment' name='showComment'> 
     </form> 

PHP:

<?php include "mysql.php"; ?> 

<?php 
    if (isset($_POST['comButon'])){ 
     $enterComment = strip_tags($_POST['enterComment']); 
      if($enterComment){ 
       $addComment = mysql_query("INSERT INTO comments(comment) VALUES('$enterComment')"); 
       if($addComment==1) 
        //INSERT INTO showComment input; 
      } 
    } 
?> 
+0

VIEWのコードはどこですか? – Hassaan

+0

PDOまたはmysqliを使用してデータベースに接続する方法の記事をお読みください。 –

答えて

0

はこれを試して、とMySQL

include "dbconnect.php"; 
if (isset($_POST['comButon'])){ 
     $enterComment = strip_tags($_POST['enterComment']); 
     if($enterComment){ 
      $addComment = mysqli_query($conn, "INSERT INTO comments(comment) VALUES('$enterComment')"); 
      if($addComment) { 
       $sql = "select comment from comments order by id desc limit 1"; 
       $result = mysqli_query($conn, $sql); 
       while($row = $result->fetch_assoc()) { ?> 
        <input type="text" value="<?php echo $row['comment']; ?>"> 
       <?php } 
      } 

     } 
} 

フォームの代わりにmysqliのを使用

<form action='' method='POST'> 
      <input type='text' id='enterComment' name='enterComment' width='400px' placeholder='Write a comment...'> 
      <input type='submit' id='combuton' name='comButon' value='Comment!'> 
      <?php if(!isset($_POST['comButon'])) { ?> 
       <input type="text" value=""> 
      <?php } ?> 
     </form> 
+0

それは動作しません、なぜ私はそれがコメントをプッシュすると思われる入力が消えた。 –

関連する問題