我已设置此代码,我想要做的是使用session从$ _POST [$ field]输出数据,以便保存它,因为我还有另一个页面,我想保存名称和注册成功后,POST的姓氏。
<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"]]);
}
?>
答案 0 :(得分:1)
您正在使用
保存会话$_SESSION['login'][$field]
但打印
$_SESSION['login'][$_POST[$field]]
您在打印
时已将数据与'<br><br>'
连接在一起
变化:
if (isset($_SESSION['login'])) {
foreach($formular as $field) {
$_SESSION['login'][$field]=$_POST[$field];
print_r($_SESSION['login'][$_POST[$field]] . '<br><br>');
}
}
到
if (isset($_SESSION['login'])) {
foreach($formular as $field) {
$_SESSION['login'][$field]=$_POST[$field];
print_r($_SESSION['login'][$field]) . '<br><br>';
}
}