for ($i=0; $i <count($_POST['name']) ; $i++) {
if (isset($_POST['name']) && isset($_POST['NIK']))
{
$_SESSION['NIK'][$i] = $_POST['NIK'][$i];
$NIK = $_SESSION['NIK'][$i];
$_SESSION['name'][$i] = $_POST['name'][$i];
$name= $_SESSION['name'][$i];
$query = mysql_query("SELECT * FROM jabatan AS t JOIN karyawn AS s WHERE s.id_jabatan LIKE t.id_jabatan AND s.nama_karyawan LIKE '%{$nama_karyawan}%' AND s.NIK LIKE '%{$NIK}%' ");
$row = mysql_fetch_array($query);
$_SESSION['job_name'] = $row['job_name'];
$_SESSION['division'] = $row['division'];
}
?>
我想问一下如何在多个输入中使用会话?
因为当我更改页面并返回该页面时,它显示错误
未定义的索引:C:\ xampp \ htdocs \ training \ output_main.php中的名称 第22行
代表代码for ($i=0; $i <count($_POST['name']) ; $i++)
请帮助我的会话工作,我只是学习PHP。
答案 0 :(得分:-1)
我认为会议不是问题,但如果你回到这个页面,我想不再有$ _POST [&#39;名称&#39;]了。
您需要检查$ _POST [&#39;名称&#39;]是否为空
if (isset($_POST['name'])) {
$postName = $_POST['name'];
} elseif (isset($_SESSION['name'])) {
$postName = $_SESSION['name'];
} else {
Die('no post or session.');
}
for ($i=0; $i <count($postName) ; $i++)
if (isset($_POST['name']) && isset($_POST['NIK']))
{
$_SESSION['NIK'][$i] = $_POST['NIK'][$i];
$NIK = $_SESSION['NIK'][$i];
$_SESSION['name'][$i] = $_POST['name'][$i];
$name= $_SESSION['name'][$i];
$query = mysql_query("SELECT * FROM jabatan AS t JOIN karyawn AS s WHERE s.id_jabatan LIKE t.id_jabatan AND s.nama_karyawan LIKE '%{$nama_karyawan}%' AND s.NIK LIKE '%{$NIK}%' ");
$row = mysql_fetch_array($query);
$_SESSION['job_name'] = $row['job_name'];
$_SESSION['division'] = $row['division'];
}
?>