检查登录仍然是一个障碍

时间:2012-02-22 06:51:18

标签: php

我的登录页面仍有问题。提取我们登录的信息的代码是最复杂的代码。我的数据库中的登录表中有四个字段,它们是这样的:`id,username,password和usertype。我想如果有人登录到他们的特权级别(使用usertype),如果用户是管理员,他们应该被定向到管理员页面而不是普通用户的页面。这段代码说:解析错误:语法错误,第65行的C:\ wamp \ www \ Learning \ Checklogin.php中的意外$结尾位于end.it看起来像这样:

enter code here
<?php


       define(DOC_ROOT,dirname(__FILE__)); // To properly get the config.php file


       $username = $_POST['username']; //Set UserName
       $password = $_POST['password']; //Set Password
       $msg ='';


       if(isset($username, $password)) {


   ob_start();


  include(DOC_ROOT.'/config.php'); //Initiate the MySQL connection


// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($username);
$mypassword = stripslashes($password);
$myusername = mysqli_real_escape_string($dbC, $myusername);
$mypassword = mysqli_real_escape_string($dbC, $mypassword);

 //Selecting all from the table
 $sql="SELECT * FROM Login WHERE Username='$myusername' and Password='$mypassword'";
  $result=mysqli_query($dbC, $sql);
if(mysql_num_rows($result) == 1)
{

    $row = mysql_fetch_array($result);
     $type = $row['Type'];

    $_SESSION['Username'] = $username;
    $_SESSION['Password'] = $mypassword;
      $_SESSION['Type'] = $type;
    $_SESSION['loggedin'] = 1;
   {

  // Mysql_num_row is counting table row
  $count=mysqli_num_rows($result);


   if($type == "Admin")
      {


      header("Location: Admin.php");

      }


      else if(type == "User")
     {
    header("Location: userpage.php");
    }


    else if($type!='Admin'or'User')
                    {
    //echo'The page can not be found';
    header("location:error1.html");

            }
     else echo'sorry';

     }
  exit();
   ?>

3 个答案:

答案 0 :(得分:3)

您的错误消息:

  

解析错误:语法错误,意外$ end

...表示文件在PHP预期之前结束。尝试检查所有开口牙箍是否有相应的闭合支撑。

答案 1 :(得分:2)

在$ _SESSION ['loggedin'] = 1;后删除额外的开口大括号。

答案 2 :(得分:1)

我看到的第一个错误就在这里:

else if(type == "User")
     {
    header("Location: userpage.php");
    }

尝试$type而不是type