To register a user, I am using a form that consists of two pages. the first form(addUser.php) sends the data over post to the second form(plz.php). In the second form I save the post values from the previous page in session variables, for example
$_SESSION['phone1'] = $_POST['telnr'];
I have checked and the data is sent correctly to the second form. The second form has only one dropdown and after an option is selected, it is supposed to save all data in the database. The problem is that when I send the second form, all session variables are overwritten and I get a error message "email cannot be null". I am assuming the other variables are overwritten too. I have tried so far saving the session data in an array and then extracting it but no luck. The second form looks like this. And yes, sessions are started at the top of each file.
$_SESSION['email1'] = $_POST['email'];
$_SESSION['passwort1'] = $_POST['passwort'];
$_SESSION['vname1'] = $_POST['vname'];
$_SESSION['fname1'] = $_POST['fname'];
$_SESSION['phone1'] = $_POST['telnr'];
$_SESSION['firma1'] = $_POST['firmen_name'];
$_SESSION['ad11'] = $_POST['adresse1'];
$_SESSION['ad21'] = $_POST['adresse2'];
$_SESSION['kr1'] = $_POST['kreis'];
//$_SESSION["plz1"] = $_POST['plz'];
if(isset($_POST['submit'])){
// Passwort wird gehasht und in der Datenbank gespeichert, bcrypt
algorithm, cost = 10, salt wurde automatisch generiert und ist unique
$hash = password_hash($_SESSION['passwort1'], PASSWORD_DEFAULT);
$insert = "INSERT INTO users
(email,passwort,vname,fname,firmen_name,telnr, userlevel, active,
adresse1, adresse2, kreis, plz) VALUES
(:email,:hash,:vname,:fname,:firma,:phone,1,0, :adresse1, :adresse2,
:kreis, :plz)";
$prepStmt = $pdo->prepare($insert);
$prepStmt ->bindParam("email", $_SESSION['email1']);
$prepStmt ->bindParam("hash", $hash);
$prepStmt ->bindParam("vname", $_SESSION['vname1']);
$prepStmt ->bindParam("fname", $_SESSION['fname1']);
$prepStmt ->bindParam("firma", $_SESSION['firma1']);
$prepStmt ->bindParam("phone", $_SESSION['phone1']);
$prepStmt ->bindParam("adresse1", $_SESSION['ad11']);
$prepStmt ->bindParam("adresse2", $_SESSION['ad21']);
$prepStmt ->bindParam("kreis", $_SESSION['kreis1']);
$prepStmt ->bindParam("plz", $_POST["plz1"]);
$prepStmt ->execute();
header("Location: users.php");
exit();
}else{
?>
<div class="container">
<div class="col-md-offset-3 col-md-7">
<form action="plz.php" method="post" class="text-center col-md-
offset-0.5 ">
<!-- more form -->