Php 将随机字符串添加到$会话
因此,我有一些代码允许用户创建自己的联盟:Php 将随机字符串添加到$会话,php,mysql,Php,Mysql,因此,我有一些代码允许用户创建自己的联盟: $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 =
$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添加到$\会话中,因为我在尝试定义索引时不断收到不同的错误 变化
$joincode = $_SESSION['joincode'];
到
当您在某个地方还有一个
会话\u start()
时,这应该可以解决这个问题 将联盟id
设置为自动增量是否有问题?这就是它存在的原因。它应该是session=variable。不是另一种方式什么样的错误?只需设置$\u SESSION['joincode']=$joincode就可以解决这个问题?而且,您的示例没有SESSION\u start()
。即使这很明显,您也需要它来跨请求激活会话存储。
$_SESSION['joincode'] = $joincode;