2016-05-09 190 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为什么它应该推送评论的输入消失了。 –

相关问题