clear message php

Asked

Viewed 38 times

0

I set up a CRUD and posted the message "Record updated successfully." to appear as soon as the registration is completed, but no matter which page I go to, the message continues, I want as soon as I click the button close he clears the message

  <div class="alert alert-<?php echo $_SESSION['type']; ?> alert-dismissible" role="alert">
    <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>    
    <?php echo $_SESSION['message']; ?> 
  </div>  
<?php endif; ?>

1 answer

0


If your goal is to present only once the message (and it is not included in the question, but I imagine there is one if(isset($_SESSION['message'])), then just do unset($_SESSION['message']); after displaying the message.

Ex:

<?php if(isset($_SESSION['message'])): ?>
  <div class="alert alert-<?php echo $_SESSION['type']; ?> alert-dismissible" role="alert">
    <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>    
    <?php echo $_SESSION['message']; ?> 
  </div>
<?php endif; ?>

Another option would be to use query strings instead of $_SESSION. Thus the value disappears when another page is loaded (or the same without the query string).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.