I try to make a session variable where the session variable name should be diffrent, and therefore i make the session variable name a variable name:
$nummer = $_POST['nummer'];
$num = $nummer;
$vareInfo = array(
"vareNummer" => "$nummer",
"vareNavn" => "$vare",
"varePris" => $pris,
"vareBillede" => $VarBillede,
"vareAntal" => $antal
);
$_SESSION[$num] = $vareInfo;
$_SESSION[$pris] = "hukabuka";
but i dosen’t work, i just changeching the the other sessioen to the new value?
it output this:
Array ( [vareNummer] => 182162
[vareNavn] => Solsikke
[varePris] => 120
[vareBillede] => 63c7cba6cac6d7.24544415.jpg
[vareAntal] => 1
)
and next time i run it it changing it instead of making a new
3
Answers
Check the session with that variable, if already set with that index then do not over write the session value
you can use either isset or !empty in php
To prevent that your session gets overwritten add a check if the session already exists.
That way it only gets created once for each unique
$num
An example how this can be made to work (using PHP 8.2):
my_form.html:
do_stuff.php:
EDIT ADD:
An example session data from posting twice from the form using two unique
data1
values would be as shown below. The values are1234
and7890
.