会话与准备好的声明

时间:2018-02-09 21:54:43

标签: php

用$ _SESSION登录后[" user_id"];进入第二页是使用准备语句的正确方法或顺序,如bind_result到stmt_fetch redeclare ??

这里是session.php

session_start();
require './database.php';

$idec = $_SESSION["user_id"];
$stmt=mysqli_stmt_init($conn);

mysqli_stmt_prepare($stmt, "SELECT user_id, name, username, password, age, 
user_type, gender FROM user WHERE user_id=?");
mysqli_stmt_bind_param($stmt, "i", $idec);
mysqli_stmt_execute($stmt);
mysqli_stmt_bind_result($stmt, $idz, $namesz, $usernamesz, $passwordsz, 
$agez, $user_typesz, $gendersz);
mysqli_stmt_store_result($stmt);

if(mysqli_stmt_num_rows($stmt) > 0){
while($rows = mysqli_stmt_fetch($stmt)){
   $idec = $idz;
   $names = $namesz;
   $usernames = $usernamesz;
   $passwords = $passwordsz;
   $ages = $agez;
   $user_types = $user_typesz;
   $genders = $gendersz;
}
}

mysqli_stmt_close($stmt);
if(!isset($idec)){
    header("Location: index.php");
} 

mysqli_close($conn); 

这是我的secondpage.php

<?php  require "session.php" ?>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<?php echo $usernames?>
</body>
</html>

0 个答案:

没有答案