Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 会话变量仅在页面刷新后设置_Php_Sql_Session - Fatal编程技术网

Php 会话变量仅在页面刷新后设置

Php 会话变量仅在页面刷新后设置,php,sql,session,Php,Sql,Session,我的会话变量仅在第二次加载页面后更改为正确的值。这种行为很奇怪,因为在第一次加载页面时,另一个会话变量matchid设置正确。未正确设置的变量如果是review number,则设置在代码段的底部 代码 很抱歉代码片段太长,但是我不知道错误在哪里: if ($stmt = $dbc->prepare("SELECT matchid, user1, user2, user1_accept, user2_accept FROM matches WHERE user1_accept = ? o

我的会话变量仅在第二次加载页面后更改为正确的值。这种行为很奇怪,因为在第一次加载页面时,另一个会话变量matchid设置正确。未正确设置的变量如果是review number,则设置在代码段的底部

代码

很抱歉代码片段太长,但是我不知道错误在哪里:

if ($stmt = $dbc->prepare("SELECT matchid, user1, user2, user1_accept, 
user2_accept FROM matches WHERE user1_accept = ? or user2_accept = ?   
LIMIT 
1")) {
$stmt->bind_param('ii', $id, $id);  // Bind id to parameter.
$stmt->execute();    // Execute the prepared query.
$stmt->store_result();

 // get variables from result.
$stmt->bind_result($matchid, $user1, $user2, $user1_accept,
 $user2_accept);
$stmt->fetch();
$num_rows = mysqli_stmt_num_rows($stmt);
if ($num_rows == 0){header('Location: /nomatches.php');}    
$_SESSION['matchid'] = $matchid;
}
print_r($_SESSION);

if ($user1 != $id){
echo 'user 1 !=';     
$reviewnumber = 'user2_accept';   
echo $reviewnumber;     
if ($stmt = $dbc->prepare("SELECT aboutme, friend, picture FROM  
userprofile
WHERE id = ? LIMIT 1")) {
$stmt->bind_param('i', $user1);  // Bind id to parameter.
$stmt->execute();    // Execute the prepared query.
$stmt->store_result();

 // get variables from result.
$stmt->bind_result($aboutme, $friend, $picture);
$stmt->fetch(); 
$picture = implode('/', array_map('rawurlencode', explode('/',     
$picture)));
}


if ($stmt = $dbc->prepare("SELECT full_name FROM users WHERE id = ? 
LIMIT 1")) {
$stmt->bind_param('i', $user1);  // Bind id to parameter.
$stmt->execute();    // Execute the prepared query.
$stmt->store_result();

 // get variables from result.
$stmt->bind_result($full_name);
$stmt->fetch(); 
}

}

if ($user2 != $id){
echo 'user 2 !=';
$reviewnumber = 'user1_accept';   
echo $reviewnumber;     
if ($stmt = $dbc->prepare("SELECT aboutme, friend, picture FROM
userprofile WHERE id = ? LIMIT 1")) {
$stmt->bind_param('i', $user2);  // Bind id to parameter.
$stmt->execute();    // Execute the prepared query.
$stmt->store_result();

 // get variables from result.
$stmt->bind_result($aboutme, $friend, $picture);
$stmt->fetch(); 
$picture = implode('/', array_map('rawurlencode', explode('/',
 $picture)));
}


if ($stmt = $dbc->prepare("SELECT full_name FROM users WHERE id = ? 
LIMIT  1")) {
$stmt->bind_param('i', $user2);  // Bind id to parameter.
$stmt->execute();    // Execute the prepared query.
$stmt->store_result();

 // get variables from result.
$stmt->bind_result($full_name);
$stmt->fetch(); 
}


 }

$_SESSION["reviewnumber"] = $reviewnumber;   

变量:reviewnumber在第一次页面加载时正确地回显,这就是为什么我不理解会话变量设置不正确的原因。

会话值是在会话值更改之前打印的-因此新会话值仅在下一次页面加载时显示。如果其他人也有类似的问题,这绝对是一件需要检查的重要事情

会话是否开始;在那里,它在哪里?另外,它是否位于使用会话的所有页面内?会话开始位于页面顶部,它也位于所有页面上。奇怪的是,其中一个会话变量是第一次设置的,而另一个没有。请尝试进一步定义它,甚至就在启动会话的位置下方。如果使用常量进一步定义,它将在第一页加载时设置。但是,这是不可能实现的,因为会话变量的值由SQL查询的结果决定。我有一行代码,直接在上面设置session变量,它会回显一行代码,所以我知道程序正在到达那个点。