Yasitha
Yasitha

Reputation: 911

session is not clearing correctly please help me on this

i made a little application to make invoices. but there is a small problem. it work like this 1) type item code or name in text box and click a button to add that item into two dimensional session variable 2) then i echo that session array item in to a table in screen.

now what the problem is, if i wanted to cancel the whole bill. i tried to unset the session array by clicking a button. but it is not working as i hope.i can clear the session only for one time. what i mean is after adding some items i cleared the session and tried to add same item again so without a problem i could do it. but again i tried to clear the session and add the same items. now it says "you are trying to add the same item twice" ( i made this error to popup when trying to add the same item without cancelling the bill)

here is my code

?>
<script type="text/javascript">
function clearsessin() {
     var actualkey = "y";
     location.href="biling.php?cmd="+actualkey;
    }
</script>
<?php if(isset($_GET['cmd'])){
session_unset();
session_destroy();
$_SESSION["bill_array"] = array();
header('location:biling.php') ;
}
?> 

Upvotes: 0

Views: 190

Answers (1)

Anton Sementsov
Anton Sementsov

Reputation: 1246

use unset($_SESSION["your_var"]); and try to do that before assignment of your session array

Upvotes: 1

Related Questions