很抱歉我的代码很难阅读,但我尽力使其易读。我正在保存此HTML表单中的会话值,我正在尝试保存新数据更改而不是旧数据更改,但我无法做到。
<body>
<div class="div">
<?php
$id=$_GET["id"];
if(isset($_SESSION['kundendaten'][$id])){
$result=$_SESSION['kundendaten'][$id];
}
?>
</div>
<form action="edit.php" method="post">
<div>Name</div><input type="text" name="name" value="<?php echo $result['vorname'];?>" required>
<div>Familyname</div><input type="text" name="familyname" value="<?php echo $result['nachname'];?>" required>
<div>Date Of Birth</div><input type="text" name="dateofbirth" value="<?php echo $result['geburtstag'];?>" required>
<div>Email</div><input type="Email" name="email" value="<?php echo $result['email'];?>" required>
<div>Telefon</div><input type="text" name="telefon" value="<?php echo $result['telefon'];?>" required>
<div>Adresse</div><input type="text" name="adresse" value="<?php echo $result['adresse'];?>" required>
<button type="submit">Save</button>
</form>
<?php
if (isset($_POST['vorname'])) {
$result['vorname']=$_POST['vorname'];
echo '<div>Vorname:</div><div class="div1">'.$result['vorname'].'</div>';
}
?>
</form>
</body>
答案 0 :(得分:1)
试试这个
<?php
$id=$_GET["id"];
if(isset($_SESSION['kundendaten'])){
$_SESSION['kundendaten']=$id;
}
$result=$_SESSION['kundendaten'];
?>
答案 1 :(得分:0)
如果要更改会话变量,则必须直接更改$_SESSION
内的值。所以只做这样的事情
<?php
if (isset($_POST['vorname'])) {
$_SESSION['vorname'] = $_POST['vorname'];
echo '<div>Vorname:</div><div class="div1">'.$_SESSION['vorname'].'</div>';
}
?>
答案 2 :(得分:0)
您可以像其他任何变量一样设置$_SESSION
:
$_SESSION['varname'] = $value;
但你必须把
session_start();
如果您希望$_SESSION
数组在页面之间保持不变,请在页面顶部显示。
答案 3 :(得分:0)
您需要先启动会话。会话值取id值
<?php
$id = $_GET["id"] ;
session_start() ;
if(isset($_SESSION['kundendaten']))
{
$_SESSION['kundendaten'] = $id ;
}
$result = $_SESSION['kundendaten'] ;
?>