PHP: Counter using Session Variables -
i need som adding value session variable using submit buttons. if define variables 0 won't count up, , if don't says:
"notice: undefined index: paperbagcount in /home/saxon/students/20151/chwi15/www/affar3/test.php on line 52"
"notice: undefined index: plasticbagcount in /home/saxon/students/20151/chwi15/www/affar3/test.php on line 59"
<?php if(!session_status() === php_session_active ) { session_start(); $_session["paperbagcount"] = 0; $_session["plasticbagcount"] = 0; } session_start(); error_reporting(-1); ?> <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>startsida</title> </head> <body> <?php if(isset($_post['addpaper'])) { $_session["paperbagcount"]+=1; } if(isset($_post['deletepaper'])) { if ($_session["paperbagcount"] == 0) { $_session["paperbagcount"] == 0; }else{ $_session["paperbagcount"]-=1; } } if(isset($_post['addplastic'])) { $_session["plasticbagcount"]+=1; } if(isset($_post['deleteplastic'])) { if ($_session["plasticbagcount"] == 0) { $_session["plasticbagcount"] == 0; }else{ $_session["plasticbagcount"]-=1; } } ?> <form method="post"> <p><label>paperbagcount</label><br> <input type="submit" name="addpaper" value="+"> <?php echo $_session["paperbagcount"] . "\n"; ?> <input type="submit" name="deletepaper" value="-"> </form> <form method="post"> <p><label>plasticbagcount</label><br> <input type="submit" name="addplastic" value="+"> <?php echo $_session["plasticbagcount"] . "\n"; ?> <input type="submit" name="deleteplastic" value="-"> </form> </body> </html>
replace php code this
<?php @session_start(); // @ avoid warning if (!isset($_session["paperbagcount"])) { $_session["paperbagcount"] = 0; } if (!isset($_session["plasticbagcount"])) { $_session["plasticbagcount"] = 0; } ?>
Comments
Post a Comment