2017-04-20 160 views
-1

我的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> 
+0

短標籤我試過它不是樂亭我將它張貼 – Pioneer2017

+0

它是什麼意思嗎? – chris85

+0

當我嘗試編輯?它不正確 – Pioneer2017

回答

0

你需要把周圍$ POST_ID

'readMore.php?id=<?= $post_id ?>' 
+0

當我把短標籤取消按鈕沒有響應,只是停留在同一頁面上,並沒有重新定向你att – Pioneer2017