如何在submiiting post后立即重定向到显示帖子的页面? [英] How to get redirected to page showing post immediately after submiiting post?
本文介绍了如何在submiiting post后立即重定向到显示帖子的页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找类似于此处发生的事情,在提交问题之后我们会被重定向到显示问题的页面。试过这样的事情:
I am looking for something like what happens here, after submitting question we get redirected to page showing question. Tried something like this:
error_reporting('E_ALL ^ E_NOTICE');
if(isset($_POST['submit'])) {
//get blog data
$title=strip_tags($_POST['title']);
$body=($_POST['body']);
$category=$_POST['category'];
if (empty($_POST['category'])) {
$er = "Please select a category from the options";
}
else if($category != "Controversies" && $category != "Entertainment" && $category != "Health" && $category != "Politics" && $category != "Lifestyle" && $category != "Technology" && $category != "Sports" && $category != "Travel"){
$er = "Please select a valid category";
}
else if (strlen($title) == 0){
$er = "Title cannot be empty";
}
else if (strlen($title) < 5) {
$er = "Make sure title is more than 5 characters";
}
else {
$stmt = $db->prepare("INSERT INTO posts (userid, title, body,category) VALUES (:userid,:title,:body,:category)");
$stmt->execute(array(':userid'=>$userid,':title'=>$title,':body'=>$body,':category'=>$category));
$sete=$db->prepare("SELECT * FROM posts WHERE title=:title AND body=:body AND userid=:userid");
$sete->execute(array(':title'=>$title,':body'=>$body,':userid'=>$userid));
$roww = $sete->fetch(PDO::FETCH_ASSOC);
$postid = $roww['postid'];
if ($sete->rowCount() > 0) {
header('Location:post.php?post='.$postid.'');
exit();
}
else {
$er = 'Some error occured please try again!';
}
}
}
?>
我没有被重定向到post.php而是重新载入空白的create_post.php。
I am not redirected to post.php instead blank create_post.php is reloaded.
推荐答案
_POST [' submit'])){
// < span class =code-comment>获取博客数据
_POST['submit'])) { //get blog data
title = strip_tags(
title=strip_tags(
_POST [' title']);
_POST['title']);
这篇关于如何在submiiting post后立即重定向到显示帖子的页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文