何时在页面刷新时显示重复的记录?

时间:2017-09-17 12:51:25

标签: php mysql

我的代码看起来像这样

当我刷新页面时,它会复制最后一个值,以避免出现此问题。这是quoa.php代码!我试过添加不同但工作正常,但仍然没有使用问题?

phpcode

<?php  
/* connection inclution code will be here */
include 'connection/conn.php';

//defining the variables to the text fields 
$question = $_POST['qst'];  
$questionext = $_POST['qsttextarea'];

//validating the text fields , if there is no text show the msg after else 
if(isset($_POST['qst']) && isset($_POST['qsttextarea'])) 
{


} else {

    $pleasefill = "please fill all the fields";
}

//sending data to the database 
$mysqlinsert = "INSERT INTO questions(qsttable,qstext) VALUES ('$question','$questionext')";

//header("Location: success.php");
if (!mysqli_query($connection,$mysqlinsert)) {
    echo " record not inserted";
} else {
 $submited = (" &nbsp;&nbsp; your question is submited please wait for the response");
}

//getting data from the database
if ($data = mysqli_query($connection,"select distinct * from questions")); {

} 
?>

显示记录代码

<?php
    while($row=mysqli_fetch_array($data)) {
        echo '
        <div id="question_div">  <span class="fa fa-chevron-right" id="spantick"></span> &nbsp;'.'<a href="#" id="qsttable">'.$row['qsttable'].'</a> <br />'.'<p id="qstext">'.$row['qstext'].' </p> </div> ' ;


    }echo '<a href="question.php?id='.$row['qid'].'"> Read more  </a>';

    ?>

1 个答案:

答案 0 :(得分:0)

您应该在输入字段中执行html验证,这样当您刷新页面时,所有字段都将为空,并且不会存储以前的值。 只需在字段中添加“必需”关键字即可。 例如。