所以我有一些代码允许用户创建自己的联盟:
$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添加到$u会话中,因为我在尝试定义索引时不断收到不同的错误。
最佳答案
改变
$joincode = $_SESSION['joincode'];
到
$_SESSION['joincode'] = $joincode;
当你在某个地方也有一个
session_start()
时,这应该可以解决这个问题。关于php - 向$ _SESSION添加随机字符串,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48075146/