您好我在登录时有一个选择选项,但我的选择值无法保持会话。我的代码有什么问题吗?请查看下面的参考代码。
我的form.php 我设置的选项值不适用于会话,但我的用户名可以保存会话
<form name=frmTest id="form" class="form-signin" action="check.php" method="post">
<div class="append-icon">
<input type="text" name="username" id="user" class="form-control form-white username" placeholder="Username" required>
<i class="icon-user"></i>
</div>
<div class="append-icon m-b-20">
<input type="password" name="password" id="pass" class="form-control form-white password" placeholder="Password" required>
<i class="icon-lock"></i>
<center>
<select name=branch class="form-control form-white username" id="branch">
<option selected> Select Branch </option>
<option value='North'> North </option>
<option value='South'> South </option>
<option value='East'> East </option>
</select>
</center>
</div>
<button type="submit" id="submit-form" class="btn btn-lg btn-danger btn-block ladda-button" data-style="expand-left">Sign In</button>
<p>
</form>
我的check.php 我插入用户名和分支,所以我可以获得两个会话,但我只能从用户名
获得会话<?php
include 'functions.php';
include 'database/connect.php';
session_start();
$user = $_POST['username'];
$branch = $_POST['branch'];
$rem = false;
if($load = $con->prepare("select * from login where username = ?")){
$load->bind_param("s", $user);
$load->execute();
$load->store_result();
$number = $load->num_rows;
$load->close();
}
if($number === 0){
echo 'Login failed';
exit();
}else{
if($active = $con->prepare("select active from login where username = ?")){
$active->bind_param("s", $user);
$active->execute();
$active->bind_result($res);
$active->fetch();
}
if($res === 0){
$_SESSION['user'] = $user;
echo 'Success';
}else{
echo 'User not activated';
}
}
?>
我的header.php和我在header.php
中包含了这个<?php
session_start();
include '../login/functions.php';
include '../login/database/connect.php';
protect();
if(isset($_SESSION['user']))
echo $_SESSION['user'];
else if(isset($_COOKIE['user']))
echo $_COOKIE['user'];
$user = $_SESSION['user'];
$branch = $_SESSION['branch'];
?>