html - How to set a counter everytime I click a submit button with Bootstrap slider in PHP

774

I'm making a survey, everytime the user press "Continuar" it goes to the next question with a slider (it's everything on the same page), I want to store how many times the user has clicked "Continuar" to make a couple of validations.

I tried to use a php session but after a couple of test echoes it doesn't seem like any of the ifs are working as it doesn't show me anything when I load my page.

<?php
    session_start();
    $f1="nulo";

    if (empty($_SESSION['cont'])){
        $_SESSION['cont']=0;
    }

    // if button is pressed, increment counter
    if(isset($_POST['submitbttn'])) {
        ++$_SESSION['cont'];
        echo $_SESSION['cont'];
    }
    if ($_SESSION['cont'] == 1){
        echo "uno";
    }    
?>
<!-- Button --> 
 <form method="post">
   <button><a href="#carouselExampleControls" role="button" data-slide="next" input type="submit" name="submitbttn">Continuar</a></button>
   <br></br>
 </form>

I expect it to show the counter so I make sure it's working and I can make the validations I have to make

People are also looking for solutions to the problem: php - PHPMailer how to add embedded image inside foreach loop

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.