我正在编写应用程序并遇到问题。我的问题是,当我保存会话变量时,我无法在另一个PHP脚本中使用它,因为它似乎没有保存变量。
在我的应用程序中,我有一个登录活动。教师登录后,应该在ListView中显示一堆学生。但是listview没有显示学生,这是因为php脚本没有传递变量。
我将在下面发布我的脚本。我希望你能帮助我。很难,因为我从应用程序中调用了所有内容?
的login.php
<?php
session_start();
if($_SERVER['REQUEST_METHOD']=='POST'){
$username = $_POST['username'];
$password = $_POST['password'];
if($username == '' || $password == ''){
echo '';
}else{
require_once('dbConnect.php');
$sql = "select * from T_Teacher where username='$username' and password='$password'";
mysqli_error($con);
$result= mysqli_fetch_assoc(mysqli_query($con,$sql));
}
if(isset($result)){
echo "success";
$_SESSION['ID_Teacher'] = $result['ID_Teacher'];
}else{
echo "Wrong Username or Password";
}
}else{
echo "Try again!";
}
?>
get_list.php
<?php
session_start();
require_once('dbConnect.php');
$sql = "SELECT T_Student.ID_Student, T_Student.Name, T_Student.Surname, T_Teacher.ID_Teacher
FROM T_Student,T_Teacher WHERE T_Student.F_ID_Teacher = .$_SESSION['ID_Arzt'] ";
$res = mysqli_query($con,$sql);
while($row = mysqli_fetch_assoc($res))
{
$output[] = $row;
}
print json_encode($output);
mysqli_close($con);
?>