-1

My add_comment.php has a input type button with value "cancel" its not redirecting the user back to the post on which he wants to comment if he press cancel .My add comment button however works perfectly .Please advise.

<?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>
Pioneer2017
  • 537
  • 2
  • 5
  • 11

1 Answers1

0

You need to put short tags around $post_id

'readMore.php?id=<?= $post_id ?>'
user2182349
  • 9,569
  • 3
  • 29
  • 41
  • when I put short tags a cancel button not responding at all its just stay on the same page and not redirects you att all – Pioneer2017 Apr 20 '17 at 01:26