Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- ?>
- <!DOCTYPE html>
- <html lang="pl">
- <head>
- <meta charset="utf-8">
- <title>S457948</title>
- <meta name="author" content="Wojciech Walis" />
- <meta name="keywords" content="Zad Dom" />
- </head>
- <body>
- <?php
- $_SESSION['liczba']=0;
- $_SESSION['srednia']=0;
- $_SESSION['suma']=0;
- $_SESSION['tab']=array();
- if(!isset($_POST['submit']) && !isset($_POST['add']) && !isset($_POST['end']))
- {
- echo '<form action="" method="post">';
- echo 'Nazwa:<input type="text" name="nazwa"><br>';
- echo '<input type="submit" name="submit" value="Zaakceptuj"><br>';
- echo '</form>';
- }else if(!isset($_POST['end']))
- {
- if(isset($_POST['submit']))
- {
- $_SESSION['name'] = $_POST['nazwa'];
- }
- if(isset($_POST['add_value']))
- {
- array_push($_SESSION['tab'],$_POST['add_value']);
- $_SESSION['suma']=$_SESSION['suma']+$_POST['add_value'];
- $_SESSION['srednia']=$_SESSION['suma']/count($_SESSION['tab']);
- }
- echo $_SESSION['name'].'<br>';
- echo 'Suma : '; print_r($_SESSION['suma']);
- echo '<br>';
- echo 'Srednia : '; print_r($_SESSION['srednia']);
- echo '<br>';
- echo '<form action="" method="post">';
- echo 'Liczba:<input type="number" name="add_value"><br>';
- echo '<input type="submit" name="add" value="Jeszcze jedna liczba">';
- echo '<input type="submit" name="end" value="Zakoncz">';
- echo '</form>';
- }else
- {
- echo 'Srednia :'.$_SESSION['srednia'].'<br>';
- echo 'Suma : '.$_SESSION['suma'].'<br>';
- echo 'Podane liczby : ';
- foreach($_SESSION['tab'] as $tmp)
- {
- echo '<br>'.$tmp.'<br>';
- }
- session_unset();
- session_destroy();
- }
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement