Add values to an array after isset()
Posted
by
user1656692
on Stack Overflow
See other posts from Stack Overflow
or by user1656692
Published on 2012-09-08T21:37:20Z
Indexed on
2012/09/08
21:37 UTC
Read the original article
Hit count: 161
I'm trying to add elements to an array after subsequent trials, but so far only one value is being added to the array. I've Googled and searched stackoverflow, and I seem to be getting only half the picture unless if I'm implementing it wrong.
There are about 40 files, which will be needed to be submited one after another, and then a value from each trial is stored in the database.
So far, this is what I've done.
$_SESSION['task2'] = array();
//Submit Task 1
if (isset($_POST['submit_task_01'])) {
$trial1_ac_sec = cleanInput($_POST['clockInputTask_01ac']);
$trial1_est_sec = cleanInput($_POST['clockInputTask_01']);
$trial1_ac = round(($trial1_ac_sec * 42.67), 2);
$trial1_est = round(($trial1_est_sec * 42.67), 2);
$trial1_judgErr = $trial1_ac - $trial1_est;
$trial_1error = round($trial1_judgErr, 2);
array_push($_SESSION['task2'],$trial_1error);
header("location: Trial_2.php");
}
//Submit Task2
if (isset($_POST['submit_task_02'])) {
$trial2_ac_sec = cleanInput($_POST['clockInputTask_02ac']);
$trial2_est_sec = cleanInput($_POST['clockInputTask_02']);
$trial2_ac = round(($trial2_ac_sec * 42.67), 2);
$trial2_est = round(($trial2_est_sec * 42.67), 2);
$trial2_judgErr = $trial2_ac - $trial2_est;
$trial_2error = round($trial2_judgErr, 2);
array_push($_SESSION['task2'],$trial_2error);
header("location: newEmptyPHPWebPage.php");
}
... and so on.. up until 40
I'm just wondering what am I doing wrong, I know that each time isset() will reload the page, and the previous data won't be available, so in that sense I thought I'd create an array for sessions and then push data in the session, however that doesn't seem to work.
If anyone has any ideas on what I can do, I'll greatly appreciate it. Thank You.
© Stack Overflow or respective owner