我的用户在登录时拥有user_ID,这会显示在网址中。但是,当保存下一个表单(thesis.php)时从'myaccount.php'移动到页面时,相同的ID仍然应该在URL中,因此他们输入的正确数据应该在数据库中的自己的ID下。目前,thesis.php页面只是使用以下代码刷新:
$err = array();
$result = mysql_query("SELECT `id` FROM `users` WHERE `banned` = '0' ORDER BY
`id` DESC");
if(isset($_SESSION['user_id']))
if(empty($_SESSION['$user_id'])) { // user not logged in; redirect to somewhere else }
if (!empty($_POST['doThesis']) && $_POST['doThesis'] == 'Save')
{
list($id) = mysql_fetch_row($result);
session_start();
// this sets variables in the session
$_SESSION['user_id'] = $id;
foreach($_POST as $key => $value)
$stamp = time();
$ckey = GenKey();
mysql_query("update users set `ctime`='$stamp', `ckey` = '$ckey' where id='$id'")
or die(mysql_error());
$row = mysql_fetch_array($result);
print_r($row);
if(empty($err)) {
$thesis_Name = mysql_real_escape_string($_POST['thesis_Name']);
$abstract = mysql_real_escape_string($_POST['abstract']);
$sql_insert = "INSERT into `thesis`
(`user_id`,`thesis_Name`,`abstract` )
VALUES
('$id','$thesis_Name','$abstract') ";
mysql_query($sql_insert,$link) or die("Insertion Failed:" . mysql_error());
}
header("Location: myaccount.php?id=' . $_SESSION[user_id] .'");
exit();
}
}
HTML:
<p align="center">
<input name="doThesis" type="submit" id="doThesis" value="Save">
</p>
答案 0 :(得分:2)
我相信你需要先调用session_start()才能进行isset($ _ SESSION ['blah'])。
尝试转移session_start();到文件顶部
<?php
session_start();
.....
the rest of your code
答案 1 :(得分:0)
在session_start();必须在顶部;
如果你想在URL中传递id var
<a href='myaccount.php?id=<? echo $id; ?>'>