Send 10 values using the POST method, values must be entered in a [closed]

-4

The goal is to send 10 values using the POST method through the form, and insert them into a vector, which will be printed later.

Anyone can help me thank you right away.

    
asked by anonymous 08.09.2017 / 01:00

1 answer

0

According to this author's comment

I have two input fields in the form, one type number and the other submit, when I submit I want the number entered in the number field to go to an array position, each new number inserted in a new position, and then with the vector already complete with the 10 numbers, print it out. "

One way to get this result is to use sessions.

PHP

session_start();

if(!empty($_POST['num']) && isset($_POST['num']) ){ 

    //contagem do numero de vezes que o formulário foi submetido
    $_SESSION['dez']=$_SESSION['dez']+1;

    $numPost = $_POST['num'];

    if ($_SESSION['num']==""){
        $_SESSION['num'] = $numPost;
    }else{
        $_SESSION['num'] = $_SESSION['num'].",".$numPost;
    }

    if ($_SESSION['dez']==10){  
        $meuarray = explode(',', $_SESSION['num']);
        print_r($meuarray);
        session_destroy();
    }

}

HTML

<form action="" method="post"> 
    <label><input type="number" name="num" value="" required><br>
    <input type="submit">
</form>
    
08.09.2017 / 09:01