간단한 코멘트 시스템을 만들고 있습니다. 페이지를 다시로드하면 처음 삽입 된 주석이 복제됩니다. request_uri로 리디렉션 할 헤더를 사용해야합니까? 나는 그것을했고 헤더 루프가되었다. 유 $ 입력을 표시하는 방법을 사전에 감사행마다 페이지 새로 고침이 중복됩니다.
public function comment($username, $comment, $code)
{
if(!empty($username) && !empty($comment) && !empty($code))
{
$date =date("Y-m-d H:i:s");
if($insert = $this->db->prepare("INSERT INTO reviews (username, comment, time) VALUES (?, ?, ?)"))
{
$insert->bind_param('sss', $username, $comment, $date);
$insert->execute();
}
else
{
echo "iets gaat mis met inserten";
}
}
else
{
echo "missing fields";
}
}
public function retrieve()
{
if($retrieve = $this->db->query("SELECT username, comment, time FROM reviews ORDER BY id LIMIT 0, 5"))
{
while($row = $retrieve->fetch_assoc())
{
$output .= '<div class="comment">';
$output .= '<div class="name">'.$row['username'].'</div>';
$output .= '<div class="date">Added at '.date('H:i \o\n d M Y',strtotime($row['time'])).'"></div>';
$output .= '<p>'.$row['comment'].'</p>';
$output .= '</div>';
}
return $output;
}
}
<?php
$reizen= new reizen;
echo $reizen->retrieve();
?>
<script type="text/javascript">
</script>
<?php
$output = '';
$output .= '<div id="contactform">';
$output .= '<form name="form" id="form" action="index.php?page=review" method="post">';
$output .= '<label>Name:</label>';
$output .= '<input type="text" name="username" />';
$output .= '<label>comment</label>';
$output .= '<textarea name="comment" rows="20" cols="20"></textarea>';
$output .= '<label><img src="captcha.php"></label>';
$output .= '<input type="text" name="code">';
$output .= '<input type="submit" class="submit" name="submit" value="Send message" />';
$output .= '</form>';
$output .= '</body>';
$output .= '</div>';
$output .= '</html>';
echo $output;
if(isset($_POST['submit']))
{
$username = $_POST['username'];
$comment = $_POST['comment'];
$code = $_POST['code'];
$reizen->comment($username, $comment, $code);
}
?>
출력으로 무엇을하고 있습니까? 그것은 내게 프런트 엔드 문제처럼 들리네 .... – Brad
코멘트를 삽입 한 직후에 페이지를 다시로드하거나 페이지를 다시로드 할 때마다 이런 일이 발생합니까? – xpy
내가 페이지를 새로 고침 할 때마다 – user2065001