[英]How to make an IF ELSE condition in PHP and MySQL query with user LOGIN info
再会。 我在这里真的需要人的帮助。 我很难考虑如何执行正确的代码。
我正在创建一个带有单个 index.php 文件的网站,其中包含 2 个标题。 我正在对要在索引上调用的 header 使用“包含”语句。 “header1.php”是网站访客的默认header,也包含“登录”按钮。 而“header2.php”是 header 对于那些已经登录他们的帐户并有一个“注销”按钮的人。
问题是,当客人访问网站时,网站会显示默认的 header,即“header1.php”。 当用户登录到他/她的帐户时,会显示“header2.php”。 我应该怎么称呼 header? 我应该在 if else 语句中写什么条件? 它可能需要访问 MySQL 数据库以获取用户数据。
例子:
<?php
if( user log in to his account ){
include 'header2.php';
}else{
include 'header1.php';
}
我的登录脚本是:
<?php
session_start();
$username = $_POST['username'];
$password = $_POST['password'];
$connect = mysqli_connect("localhost", "root", "", "yfcgk_canlaon");
$query = mysqli_query($connect, "SELECT * from members WHERE USERNAME = '$username' and PASSWORD = '$password'");
$count = mysqli_num_rows($query);
if($count <= 0 ){
session_start();
header("location:index.php?error");
}else{
$_SESSION['user'] = 1;
$_SESSION['username'] = ucwords($username);
header("location:index.php");
}
?>
可能是这个
if ($_SESSION['user'] && $_SESSION['user'] == 1) {
include 'header2.php';
}else{
include 'header1.php';
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.