0

我的用户在登录时有一个 user_ID,它出现在 URL 中。但是,当保存下一个表单(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>
4

2 回答 2

2

我相信您需要先调用 session_start(),然后才能执行 isset($_SESSION['blah'])。

尝试转移 session_start(); 到文件顶部

<?php
session_start();
.....
the rest of your code
于 2012-04-13T20:49:48.273 回答
0

session_start(); 必须在顶部;

如果您想在 URL 中传递 id var,请使用

<a href='myaccount.php?id=<? echo $id; ?>'>
于 2012-04-13T20:49:58.530 回答