Each time I press addproduct button my array is emptied. I assume that is because of the $productarray = array(); declaration, but I want to keep what I’ve added into it each time. So, if I press addproduct twice, I want first entry to stay intact. I will have another button that redirects the user to next page but before that clears the array;
$productarray = array();
if(isset($_POST['addproduct'])){
$prod = trim(mysql_real_escape_string(stripslashes(htmlspecialchars($_POST['prodcall']))));
array_push($productarray,$prod);
}
print_r($productarray);
Looking for a way that hopefully does not need to use SQLDB or SESSION.
Once the execution of script completes, all variables declared are destructed by itself. As an alternate to this you can take advantage of Session variable
$_SESSIONor a Temporary table in database. JavaScript can also help if you change it to a button rather than a submit button.