Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: php sessions

  1. #1
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    php sessions

    Hi i have a html page with a simple form and i want to be able to input only INTS, and after i press submit i wana be on the same page and the value gets stored in an array, until some1 enters zero and it will then show how many ints you have entered. i think the it should be done with sessions, here is my code:

    html:

    <html>
    <body>

    <form action="test.php" method="post">
    Heltal: <input type="text" name="tal" />
    Heltal: <input type="text" name="tal2" />

    <input type="submit" />
    </form>


    </body>
    </html>,



    <html>
    <body>




    php:

    <?php


    $tal = array ($_POST['tal'],$_POST['tal2']);

    foreach ($tal as $koll => $value) {
    if (ctype_digit($value)) {
    echo "The string $koll consists of all digits."."</br>";
    } else {
    echo "The string $koll does not consist of all digits."."</br>";
    }
    }

    $sum = array_sum($tal);
    echo "Summan:".$sum."</br>";

    $antal = count($tal);
    echo "Antalet tal: ".$antal."</br>";

    $medel = $sum/$antal;
    echo "Medelvärdet: ". $medel;

    ?>
    </body>
    </html>

  • #2
    Banned
    Join Date
    Oct 2012
    Posts
    81
    Thanks
    0
    Thanked 4 Times in 4 Posts
    yep your right. this can be done with sessions. do you no how to use sessions in php?

    also just a quick tip. if you wanna send an array of values from a form, give the elements the same name suffixed with []

    Code:
    Heltal: <input type="text" name="tal[]" />
    Heltal: <input type="text" name="tal[]" />
    and then in your php
    PHP Code:
    foreach($_POST['tal'] as $val){

        
    //do something with each $val here




  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •