[英]How to show comment posted instantly after submitting
I am using ISSET condition to add comment on the page after saving it to database. 保存到数据库后,我正在使用ISSET条件在页面上添加注释。
if (ISSET($_POST['comment_submit'])) {
$comment_author = $_POST['comment_author'];
$comment_content = $_POST['comment_content'];
$post_id = $_POST['post_id'];
if ($comment_content!="") {
$new_comment = mysql_query("INSERT INTO comment (post_id, comment_author, comment_content, comment_date) VALUES ('$post_id', '$comment_author','$comment_content', now())");
}
}
but after redirecting to same page its not showing comment posted recently. 但是重定向到同一页面后,它没有显示最近发布的评论。 On refersh it starts displaying.
在referh上,它开始显示。
将在数据库中插入数据的代码放在插入查询之后。
If you are redirecting the user to same page, you won't get values in $_POST variable, since the form is not submitted again. 如果将用户重定向到同一页面,则不会在$ _POST变量中获取值,因为不会再次提交表单。 You may have to store comment_author and comment_content values in session or you may have to pass these values while refreshing the page.
您可能必须在会话中存储comment_author和comment_content值,或者可能必须在刷新页面时传递这些值。
it seems that you're using pure php only. 看来您只使用纯PHP。
header("Location: url") 标头(“位置:网址”)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.