欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

代码-自学PHP mysql web开发小次鸟,寻求大神帮助 第23章会话控制

程序员文章站 2024-01-14 13:07:10
...
代码控制php会话

代码运行一直提示我第23行有错误
session_start();//开始会话

if (isset($_POST['userid'])&&isset($_POST['password']))
{//使用者尝试登录
$userid=$_POST['userid'];
$password=$_POST['password'];

$db_conn=new mysqli('localhost','root','','auth');

if(mysqli_connect_errno()){
echo 'Connection to database failed:'.mysqli_connect_error();
exit();
}

$query='select * from authorised_users'
."where name='$userid'"
."and password='$password'";

$result=$db_conn->query($query);
if ($result->num_rows >0) {
$_SESSION['valid_user']=$userid;
}

$db_conn->close();
}
?>


home page

if(isset($_SESSION['valid_user']))
{
echo 'you are logged in as'.$_SESSION['valid_user'].'
';
echo 'log out
';

}
else
{
if (isset($userid))
{
echo 'Could not log you in.
';
}
else
{
echo 'you are not logged in';
}

echo'

';
echo'';
echo'';
echo'';
echo'';
echo'';
echo'';
echo'
Userid:
password:
';
echo'
';
}
?>


Members section