所以我有一些代码允许用户创建他们自己的联盟:
$unique_id = $_SESSION['unique_id'];
$leaguename = $link->escape_string($_POST['league_name']);
$startdate = $link->escape_string($_POST['start_date']);
$enddate = $link->escape_string($_POST['end_date']);
$joincode = $link->escape_string( md5( rand(0,1000) ) );
//query for the highest league Number
$leagueid = $link->query("SELECT MAX(league_id) as max_league_id FROM leagues")->fetch_assoc()['max_league_id'];
//add one to the highest
$leagueid++;
//insert league data
$sql = "INSERT INTO leagues (unique_id, league_id, league_name, start_date, end_date, joincode) "
. "VALUES ('$unique_id','$leagueid','$leaguename','$startdate','$enddate','$joincode')";
mysqli_query($link,$sql);
$joincode = $_SESSION['joincode'];
?>
如何将$ joincode添加到$ _SESSION中,因为我在尝试定义索引时只是不断收到错误。
答案 0 :(得分:2)
更改
$joincode = $_SESSION['joincode'];
到
$_SESSION['joincode'] = $joincode;
当你在某处有一个session_start()
时,这应该解决它。