2017-07-16 37 views
-2

我尝试做一个登录表单,将引导用户的index.html如果所有3个条件是真正的用户:PHP验证只在DB“活跃”值可以登录

  • 用户名正确
  • 密码正确
  • 用户处于Active状态(我有列的状态在我的DB(枚举:激活/未激活)

我设法让我的网页,以验证用户名和密码继承人我的代码:

<?php 
    session_start(); 

    if(isset($_POST['login'])) { 
     include_once("dbconfig.php"); 
     $username = mysqli_real_escape_string($koneksi,$_POST['username']); 
     $password = mysqli_real_escape_string($koneksi,$_POST['password']); 

     $sql = "SELECT id FROM usersss WHERE username='$username' AND password='$password'AND status='Active'"; 
     $query = mysqli_query($koneksi, $sql); 
     $row = mysqli_fetch_array($query, MYSQLI_ASSOC); 

     $count = mysqli_num_rows($query); 

     if($count == 1) { 
      $_SESSION['username'] = $username; 

      header("Location: index.php"); 
     } else { 
      header("Location: invalid.php"); 
     } 

    } 
?> 

任何人都可以帮助我包含IF语句,因此它只会验证在我的数据库中有'Active'值的用户登录。谢谢!

+0

在查询中添加此你solect只有具有状态=“活动”用户..所以,如果你得到结果这是一个活跃的用户.. – scaisEdge

+0

欢迎来到堆栈溢出!你似乎在要求某人为你写一些代码。堆栈溢出是一个问答网站,而不是代码写入服务。请[see here](http://stackoverflow.com/help/how-to-ask)学习如何编写有效的问题。 – herrbischoff

回答

0

首先,你必须编辑您的查询

$sql = "SELECT id FROM usersss WHERE username='$username' AND password='$password'"; 

然后if语句

if($count == 1) { 
if($row['status']=="Active"){ 
     $_SESSION['username'] = $username; 
     header("Location: index.php"); 
    } else { 
//redirect to invalid.php 
//end main if statement of ($count==1) 
+0

我试过它工作!我试着修改你的代码,这样如果用户键入错误的用户名/密码,那么他们将被定向到:invalid.php,如果他们不是活动用户,他们将被定向到notactive.php。 我的代码将直接incorect和不活跃的用户invalid.php ....你能帮我指导他们不同吗?谢谢@Osama – milan