gbenga wale
gbenga wale

Reputation: 359

Unsetting session in PHP

I have a form which is used to insert records into the database and if all goes right redirect the user to the index page with a message (actually set with a session) about the success or failure of the operation.

Now, am able to set the session in add_book.php and display the message in index.php but the message still persist after reloading the page without going away.

in add_book.php. I have this

$_SESSION['insert'] = "Record inserted into the database";
                        session_regenerate_id();
                        session_write_close();
                        echo '...succesfully add new book...';
                        header("Location: index.php");
                        exit();  

and in the index.php, I have this

<?php if(isset($_SESSION['insert'])){
?>
<p class="update"><?php echo $_SESSION['insert'];?></p>
<?php
}//end of isset $_SESSION['insert']
?>

Upvotes: 0

Views: 53

Answers (2)

Orange Orange
Orange Orange

Reputation: 1981

try deleting the content of your session variable

 <p class="update"><?php echo $_SESSION['insert']; $_SESSION['insert'] = "";?></p>

Upvotes: 1

Manikiran
Manikiran

Reputation: 1

Try deleting the session after displaying:

<?php if(isset($_SESSION['insert'])){
?>
<p class="update"><?php echo $_SESSION['insert'];?></p>
<?php
unset($_SESSION['insert']);
}//end of isset $_SESSION['insert']
?>

Upvotes: 3

Related Questions