As I mentioned in comments, you need to use sessions for this in order to increment a number each time the button for it is clicked.
I have to admit that I pulled/borrowed the following from this answer (which I upvoted I might add).
N.B: A second version of the following exists just below it.
If used in the same file:
<?php
session_start();
if(isset($_POST['reset'])){
unset($_SESSION['number']);
session_destroy();
$_SESSION['number']=0;
}
if(!isset($_SESSION['number'])){
$_SESSION['number']=1;
}elseif(isset($_POST['next'])){
$_SESSION['number']++;
}
echo '
<form action="" method="POST">
<input class="big_b" type="submit" name="next" value="Add to cart" />
<input type="submit" name="reset" value="Reset" />
</form>';
echo $_SESSION['number'];
If used in two files:
File 1:
<?php
echo '
<form action="next_page.php" method="POST">
<input class="big_b" type="submit" name="next" value="Add to cart" />
<input type="submit" name="reset" value="Reset" />
</form>';
File 2: (next_page.php)
<?php
session_start();
// Reset to 1
if(isset($_POST['reset'])){
unset($_SESSION['number']); // unset the session
session_destroy(); // make sure the session is destroyed
$_SESSION['number']=0; // reset it back to zero
}
if(!isset($_SESSION['number'])){
$_SESSION['number']=1;
}elseif(isset($_POST['next'])){
$_SESSION['number']++;
}
echo $_SESSION['number'];
Reference:
How to check if a session is equal to a certain number:
You can also check if the session is set and is equal to a certain number:
if(isset($_SESSION['number']) && $_SESSION['number'] == 5) {
echo "You have reached 5. The session has been reset back to zero.";
unset($_SESSION['number']);
session_destroy();
$_SESSION['number']=0;
}