Reputation: 31
I have set this code, what i would like to do is to output the data from $_POST[$field] using session so that it will be saved,because i also have another page that i want to save the name and the family name from POST after successful registration.
<body>
<?php
if (isset($_POST["vorname"]) && isset($_POST["nachname"]) && isset($_POST["geburtstag"])&&
isset($_POST["email"]) && isset($_POST["telefon"]) && isset($_POST["adresse"]))
$formular = array('vorname','nachname','geburtstag','email','telefon','adresse');
if (isset($_SESSION['login'])) {
foreach($formular as $field) {
$_SESSION['login'][$field]=$_POST[$field];
print_r($_SESSION['login'][$_POST[$field]] . '<br><br>');
}
}
?>
<div class="div">
<form action="login.php" method="post">
<div>Vorname </div><input type="text" name="vorname" required>
<span class="error"><?php echo $vornameErr;?></span>
<div>Nachname </div><input type="text" name="nachname" required>
<span class="error"><?php echo $nachnameErr;?></span>
<div>Geburtstag</div><input type="text" name="geburtstag" required>
<span class="error"><?php echo $geburtstagErr;?></span>
<div>Email </div><input type="Email" name="email" required>
<span class="error"><?php echo $emailErr;?></span>
<div>Telefon </div><input type="text" name="telefon" required>
<span class="error"><?php echo $telefonErr;?></span>
<div>Adresse </div><input type="text" name="adresse" required>
<span class="error"><?php echo $adresseErr;?></span><br>
<button type="submit">Submit</button>
</form>
</div>
<br>
<a href="kunden.php">kunden</a>
</body>
</html>
And this is the other page that i want to save the name and family name in to it using session
<?php
$a=array(
array('mousa','123'),
array('',''));
if(isset($_POST["name"]) && isset($_POST["password"]))
if(in_array(array($_POST["name"],$_POST["password"]),$a)){
header('Location:login.php');
}
if (isset($_SESSION['login'])) {
print_r($_SESSION['login'][$_POST["vorname"]]);
}
?>
Upvotes: 0
Views: 57
Reputation: 1046
You are saving in session using
$_SESSION['login'][$field]
but printing
$_SESSION['login'][$_POST[$field]]
and you have concatenated the data with '<br><br>'
when printing
Change:
if (isset($_SESSION['login'])) {
foreach($formular as $field) {
$_SESSION['login'][$field]=$_POST[$field];
print_r($_SESSION['login'][$_POST[$field]] . '<br><br>');
}
}
to
if (isset($_SESSION['login'])) {
foreach($formular as $field) {
$_SESSION['login'][$field]=$_POST[$field];
print_r($_SESSION['login'][$field]) . '<br><br>';
}
}
Upvotes: 1