PHP不重定向到所需页面
问题描述:
我的add_comment.php有一个输入类型的按钮,其值为“cancel”,它不会将用户重定向到他想要评论的帖子,如果他按下取消。 。请指教。PHP不重定向到所需页面
<?php
require_once 'app/helper.php';
session_name('mypaperplane');
session_start();
if (!verify_client()) {
header('location: signin.php');
}
$title='Add new comment';
$error="";
if(isset($_POST['submit'])){
$comments = filter_input(INPUT_POST,'comment', FILTER_SANITIZE_STRING);
$comments = trim($comments);
$post_id = filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT);
$post_id = trim($post_id);
if (! $comments) {
$error='*Comment field is required';
}else{
$com_link = mysqli_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PWD, MYSQL_DB);
$uid = $_SESSION['user_id'];
$post_id = mysqli_real_escape_string($com_link, $post_id);
$comments = mysqli_real_escape_string($com_link, $comments);
$comsql="INSERT INTO comments VALUES('',$post_id,$uid,'$comments', NOW())";
$comresult = mysqli_query($com_link,$comsql);
if($comresult && mysqli_affected_rows($com_link)>0){
header("location:readMore.php?id=$post_id");
}else{
header("location:readMore.php?id=$post_id");
}
}
}
?>
<div class="content">
<?php include'tpl/header.php'; ?>
<form name="comment" method="post">
<label for="comment">Comment here:</label><br><br>
<textarea rows="15" cols="15" name="comment" id="comment"></textarea><br><br>
<input type="submit" name="submit" value="Add comment" onclick="window.location='readMore.php?id= <?= $post['id']; ?>';">
<input type="button" value="Cancel" onclick="window.location.href='readMore.php?id=$post_id'"><br><br>
<span class="errorB"><?= $error; ?></span>
</form>
<?php include'tpl/footer.php'; ?>
</div>
答
你需要把周围$ POST_ID
'readMore.php?id=<?= $post_id ?>'
+0
当我把短标签取消按钮没有响应,只是停留在同一页面上,并没有重新定向你att – Pioneer2017
短标签我试过它不是乐亭我将它张贴 – Pioneer2017
它是什么意思吗? – chris85
当我尝试编辑?它不正确 – Pioneer2017