我在尝试弄清楚如何在登录时获取部门的会话值时遇到问题。用户默认值在user_info表中设置。当他们登录时,它会抓取并将其存储在名为dept的会话中。这样我就可以通过应用程序使用了。我想要做的是允许用户键入一个新的部门并将部门会话更改为他们在输入框中键入的部分。我尝试在profile.php页面上添加$ _Get或$ _POST,因为一旦用户登录它就会进入该页面。我没有运气它只是显示为空白。任何帮助,将不胜感激。如果我得到它,我将继续试图解决它并发布答案。
index.php
<div style="width: 300px;">
<div class="panel panel-primary">
<div class="panel-heading">Login</div>
<div class="panel-heading">
<label for="lanId">lanId</label>
<input type="text" class="form-control" id="lanId">
<label for="lanId">Password</label>
<input type="password" class="form-control" id="password" name="password">
<input type="text" class="from-control" placeholder="change department" id="department" name="department">
<p><br></p>
<input type="submit" class="btn btn-success" style="float: right;bottom:12px;" id="login" value="Login" name="login">
</div>
的login.php
<?php
include('dbconnect.php');
session_start();
if(isset($_POST['userLogin'])){
$lanId=mysqli_real_escape_string($conn,$_POST['lanId']);
$pwd=md5($_POST['pwd']);
$sql="SELECT * FROM user_info WHERE lanId='$lanId' AND password='$pwd'";
$run_query=mysqli_query($conn,$sql);
$count=mysqli_num_rows($run_query);
if($count==1){
$row=mysqli_fetch_array($run_query);
$_SESSION['uid']=$row['user_id'];
$_SESSION['uname']=$row['employee_name'];
$_SESSION['dept']=$row['department'];
$_SESSION['lanId']=$row['lanId'];
echo "true";
}
}
?>
main.js
$("#login").click(function(event){
event.preventDefault();
var lanId=$('#lanId').val();
var pwd=$('#password').val();
console.log(pwd);
$.ajax({
url: "login.php",
method: "POST",
data: {userLogin:1,lanId:lanId, pwd:pwd},
success: function(data){
if(data=="true"){
window.location.href="profile.php";
}
}
})
})
这是个人资料页面的开头。 profile.php
<?php
session_start();
if(!isset($_SESSION['uid'])){
header('Location:index.php');
}
?>
答案 0 :(得分:0)
首先,您需要在ajax请求中传递您的部门值,如下所示
<ui-select ng-model="customer.selected as ABC" theme="bootstrap">
<ui-select-match placeholder="">{{$select.selected.customer_company_name}}</ui-select-match>
<ui-select-choices repeat="customer in customers | filter: $select.search">
<div ng-bind-html="customer.customer_company_name | highlight: $select.search"></div>
</ui-select-choices>
</ui-select>
})
然后在login.php
$("#login").click(function(event){
event.preventDefault();
var lanId=$('#lanId').val();
var pwd=$('#password').val();
var dept=$('#department').val();
console.log(pwd);
$.ajax({
url: "login.php",
method: "POST",
data: {userLogin:1,lanId:lanId, pwd:pwd,dept:dept},
success: function(data){
if(data=="true"){
window.location.href="profile.php";
}
}
})
希望它的工作。