造成这种情况的原因是什么?我认为这是一个浏览器问题,但我检查它对我来说很好..
对于丢失的会话变量,数据库INSERT也会失败..
我在专用服务器上使用smarty,php 5和apache。这是我正在复制的代码的一部分......
当$ _SESSION [' user']为空时,mysql_insert_id()也变为NULL。
<?php
session_start();
if(!isset($_SESSION['user']))
{
header("Location: /login.php");
}
mysql_query("INSERT into press_releases
(`date`,`category`,`title`,`desc`,`body`,`company`,`address`,`tel`,`url`,`keywords`
,`email`,`contribution`,`sponsored`,`user_ip`)
VALUES
('$date','$data[category]','$data[title]','$data[desc]','$data[content]','$data[company]', '$data[address]','$data[tel]','$data[url]'
,'$data[keywords]','$_SESSION[user]','$contribution','$sponsored','$user_ip')
",$link) or die("Insertion Failed:" . mysql_error());
// echo "<h3>Thank You</h3> We received your submission.";
$id = mysql_insert_id($link);
// IMPORTANT: Place front slash here when uploaded to server
?>