2016-05-09 284 views
-1

我試圖顯示一些信息存儲在MySQL評論表輸入,但我有問題。輸入名爲enterComment將數據插入到我的數據庫中,並且我希望它重新導向回到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

試試這個,並使用mysqli的,而不是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 } 
      } 

     } 
} 

表單的

<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

它不起作用,Idk爲什麼它應該推送評論的輸入消失了。 –

相關問題