嘿我试图将输入中的数据发送到$ _SESSION变量中,但是当我被重定向到页面时,我得到了未定义的索引:idEmployee 。这是我的方法。
第一页的代码
session_start();
include('../includes/config.php');
include('../includes/db.php');
if (isset($_POST['updateEmployee'])) {
if (isset($_POST['tempId'])) {
$myVar = $_POST['tempId'];
$_SESSION['idEmployee'] = $myVar;
header("Location:nuevoCliente.php");
}
}
?>
<?php
$query = "SELECT employee.employee_id, employee.employee_name, employee.employee_cc, type_employee.t_Employee_name FROM employee, type_employee WHERE employee.t_Employee_id = type_employee.t_Employee_id";
global $db;
$result = $db->query($query);
while($row = mysqli_fetch_array($result)){
echo "<tr><td style='text-align:center'>" .
$row['employee_name'] . "</td><td style='text-align:center'>" .
$row['employee_cc'] . "</td><td style='text-align:center'> " .
$row['t_Employee_name'] . "</td>" .
"<td style='text-align:center; vertical-align:inherit'>" .
"<form style='margin-bottom: initial;' method='post' action='nuevoCliente.php'>" .
"<input type='hidden' name='tempId' value='" . $row['employee_id'] . "'/>";
echo $row['employee_id'] ;
echo "<input class='btn btn-primary btn-block' name='updateEmployee' type='submit' value='Modificar'/></form></td></tr>";
}
echo "</table></div>";
?>
第二页的代码
<?php
session_start();
include('../includes/config.php');
include('../includes/db.php');
echo $_SESSION['idEmployee'];
?>
我做错了什么?提前谢谢。
编辑:未定义索引:idEmployee 已解决。使用var_dump($ _ SESSION),我意识到[&#39; idEmployee&#39;]并不存在,所以我只是用echo $ _SESSION [&#39; tempId&#39;]来改变问题已经不见了
第二页的代码
<?php
session_start();
include('../includes/config.php');
include('../includes/db.php');
echo $_SESSION['tempId'];
?>
现在的错误是&#39; tempId&#39;变量总是一样的,无论我在表中选择什么样的员工。有任何想法吗??非常感谢。