Php 尝试将数据提取到我的仪表板登录名codeigniter时出错

Php 尝试将数据提取到我的仪表板登录名codeigniter时出错,php,codeigniter,fetch,Php,Codeigniter,Fetch,我做了一个登录系统,它工作正常。。它会打开不同的页面,具体取决于写入的用户名和密码是对应于管理员还是简单用户 看一看: 但是,当我想在“用户页面”中添加一个表时,出现了以下错误: 行错误: </head> <body> <div class="container"> <h3>Login</h3> <hr>

我做了一个登录系统,它工作正常。。它会打开不同的页面,具体取决于写入的用户名和密码是对应于管理员还是简单用户

看一看:

但是,当我想在“用户页面”中添加一个表时,出现了以下错误:

行错误:

        </head>

        <body>
            <div class="container">
            <h3>Login</h3>
            <hr>
            <form action="<?php echo base_url('login/do_login')?>" method="POST">
                <div class="form-group">
                    <label for="cari">USERNAME</label>
                    <input type="text" name="usuario" id="usuario" class="form-control">

                </div>

                <div class="form-group">
                    <label for="cari">PASSWORD</label>
                    <input type="password" name="contrasena" id="contrasena" class="form-control">

                </div>

                <input class="btn btn-primary" type="submit" value="Login" name="login">
                <input class="btn btn-primary" type="reset" value="Reset">

            </form>
                </div>



        </body>
</html>
    <?php

        Class Login extends CI_Controller{


        public function index(){


           $this->load->view('login_form');


        }

 public function do_login()
        {
         // load the form_validation library
         $this->load->library('form_validation');

         $this->form_validation->set_rules('usuario', 'Username', 'trim|required|min_length[3]|alpha_numeric');
         $this->form_validation->set_rules('contrasena', 'Password', 'trim|required|min_length[6]');

           // if there is errors
         if ($this->form_validation->run() == FALSE) { 
            // this will load your form with the errors

               $this->load->view('login_form'); 

         } else {
           // if no errors we will hit the database
            $user=$this->input->post('usuario', true);
            $pass=$this->input->post('contrasena', true);
            $cek = $this->m_login->proceso_login($user,$pass);
            $hasil=count($cek);

            if($hasil > 0){

                $pelogin =$this->db->get_where('usuarios',array('username' => $user, 'password' => $pass))->row();

                if($pelogin ->type == 0){
                    redirect('login/admin');
                }

                else{
                    redirect('login/usuario');
                }
            }
            redirect('login/index');
        }
    }


            public function home(){

                $data['records']=$this->m_login->getDetails();
                $this->load->view('usuario',$data);
            }
        public function getDetails()
        {
            $st=$this->db->SELECT('cursadas.*, usuarios.name as usuarios, materias.name as materias_name')->from('cursadas')
                ->join('usuarios','usuarios.id=cursadas.user_id')
                ->join('materias','materias.id=cursadas.subject_id')
                ->WHERE('cursadas.user_id=',$this->session->userdata['id'])
                ->get()->result_array();
            return $st[0]; // or use the row function
        }
                <table class="table table-hover" align="center" border="1" cellspacing="0" cellpadding="0" width="700" id="tabla_busqueda">
                <thead>
                    <th>id</th>
                    <th>User</th>
                    <th>Subject</th>
                    <th>Grade</th>
                    <th>Date</th>
                </thead>


<tbody>
    <?php

    if (count($records) > 0) {
        foreach($records as $record) {

            echo "<tr>
                      <td>".$record['id']."</td>
                      <td>".$record['User']."</td>
                      <td>".$record['name']."</td>
                      <td>".$record['grade']."</td>
                      <td>".$record['date']."</td>
                  </tr>";
        }

       }
    ?>

</tbody>

</body>
</html>
if($hasil > 0)
{

   $pelogin =$this->db->get_where('usuarios',array('username' => $user, 'password' => $pass))->row();
  // here $pelogin has the id of the user 
 // create session like this 
  $this->session->set_userdata(array('id' => $pelogin->id));
//  OR  like this 
// $this->session->set_userdata('id', $pelogin->id);

  if($pelogin ->type == 0)
  {
    // here goes  the admin data 
     redirect('admin');
  }

  else{
           //call here usuario method which has user data who logged in like
             redirect('usuario');
          // OR
          // Call some method which has user data in $records and 
      }
}

不知道该怎么办:/

这是我的完整代码:

我的登录视图文件(“登录表单”):

        </head>

        <body>
            <div class="container">
            <h3>Login</h3>
            <hr>
            <form action="<?php echo base_url('login/do_login')?>" method="POST">
                <div class="form-group">
                    <label for="cari">USERNAME</label>
                    <input type="text" name="usuario" id="usuario" class="form-control">

                </div>

                <div class="form-group">
                    <label for="cari">PASSWORD</label>
                    <input type="password" name="contrasena" id="contrasena" class="form-control">

                </div>

                <input class="btn btn-primary" type="submit" value="Login" name="login">
                <input class="btn btn-primary" type="reset" value="Reset">

            </form>
                </div>



        </body>
</html>
    <?php

        Class Login extends CI_Controller{


        public function index(){


           $this->load->view('login_form');


        }

 public function do_login()
        {
         // load the form_validation library
         $this->load->library('form_validation');

         $this->form_validation->set_rules('usuario', 'Username', 'trim|required|min_length[3]|alpha_numeric');
         $this->form_validation->set_rules('contrasena', 'Password', 'trim|required|min_length[6]');

           // if there is errors
         if ($this->form_validation->run() == FALSE) { 
            // this will load your form with the errors

               $this->load->view('login_form'); 

         } else {
           // if no errors we will hit the database
            $user=$this->input->post('usuario', true);
            $pass=$this->input->post('contrasena', true);
            $cek = $this->m_login->proceso_login($user,$pass);
            $hasil=count($cek);

            if($hasil > 0){

                $pelogin =$this->db->get_where('usuarios',array('username' => $user, 'password' => $pass))->row();

                if($pelogin ->type == 0){
                    redirect('login/admin');
                }

                else{
                    redirect('login/usuario');
                }
            }
            redirect('login/index');
        }
    }


            public function home(){

                $data['records']=$this->m_login->getDetails();
                $this->load->view('usuario',$data);
            }
        public function getDetails()
        {
            $st=$this->db->SELECT('cursadas.*, usuarios.name as usuarios, materias.name as materias_name')->from('cursadas')
                ->join('usuarios','usuarios.id=cursadas.user_id')
                ->join('materias','materias.id=cursadas.subject_id')
                ->WHERE('cursadas.user_id=',$this->session->userdata['id'])
                ->get()->result_array();
            return $st[0]; // or use the row function
        }
                <table class="table table-hover" align="center" border="1" cellspacing="0" cellpadding="0" width="700" id="tabla_busqueda">
                <thead>
                    <th>id</th>
                    <th>User</th>
                    <th>Subject</th>
                    <th>Grade</th>
                    <th>Date</th>
                </thead>


<tbody>
    <?php

    if (count($records) > 0) {
        foreach($records as $record) {

            echo "<tr>
                      <td>".$record['id']."</td>
                      <td>".$record['User']."</td>
                      <td>".$record['name']."</td>
                      <td>".$record['grade']."</td>
                      <td>".$record['date']."</td>
                  </tr>";
        }

       }
    ?>

</tbody>

</body>
</html>
if($hasil > 0)
{

   $pelogin =$this->db->get_where('usuarios',array('username' => $user, 'password' => $pass))->row();
  // here $pelogin has the id of the user 
 // create session like this 
  $this->session->set_userdata(array('id' => $pelogin->id));
//  OR  like this 
// $this->session->set_userdata('id', $pelogin->id);

  if($pelogin ->type == 0)
  {
    // here goes  the admin data 
     redirect('admin');
  }

  else{
           //call here usuario method which has user data who logged in like
             redirect('usuario');
          // OR
          // Call some method which has user data in $records and 
      }
}
和我的仪表板“usuario”(用户页面):

        </head>

        <body>
            <div class="container">
            <h3>Login</h3>
            <hr>
            <form action="<?php echo base_url('login/do_login')?>" method="POST">
                <div class="form-group">
                    <label for="cari">USERNAME</label>
                    <input type="text" name="usuario" id="usuario" class="form-control">

                </div>

                <div class="form-group">
                    <label for="cari">PASSWORD</label>
                    <input type="password" name="contrasena" id="contrasena" class="form-control">

                </div>

                <input class="btn btn-primary" type="submit" value="Login" name="login">
                <input class="btn btn-primary" type="reset" value="Reset">

            </form>
                </div>



        </body>
</html>
    <?php

        Class Login extends CI_Controller{


        public function index(){


           $this->load->view('login_form');


        }

 public function do_login()
        {
         // load the form_validation library
         $this->load->library('form_validation');

         $this->form_validation->set_rules('usuario', 'Username', 'trim|required|min_length[3]|alpha_numeric');
         $this->form_validation->set_rules('contrasena', 'Password', 'trim|required|min_length[6]');

           // if there is errors
         if ($this->form_validation->run() == FALSE) { 
            // this will load your form with the errors

               $this->load->view('login_form'); 

         } else {
           // if no errors we will hit the database
            $user=$this->input->post('usuario', true);
            $pass=$this->input->post('contrasena', true);
            $cek = $this->m_login->proceso_login($user,$pass);
            $hasil=count($cek);

            if($hasil > 0){

                $pelogin =$this->db->get_where('usuarios',array('username' => $user, 'password' => $pass))->row();

                if($pelogin ->type == 0){
                    redirect('login/admin');
                }

                else{
                    redirect('login/usuario');
                }
            }
            redirect('login/index');
        }
    }


            public function home(){

                $data['records']=$this->m_login->getDetails();
                $this->load->view('usuario',$data);
            }
        public function getDetails()
        {
            $st=$this->db->SELECT('cursadas.*, usuarios.name as usuarios, materias.name as materias_name')->from('cursadas')
                ->join('usuarios','usuarios.id=cursadas.user_id')
                ->join('materias','materias.id=cursadas.subject_id')
                ->WHERE('cursadas.user_id=',$this->session->userdata['id'])
                ->get()->result_array();
            return $st[0]; // or use the row function
        }
                <table class="table table-hover" align="center" border="1" cellspacing="0" cellpadding="0" width="700" id="tabla_busqueda">
                <thead>
                    <th>id</th>
                    <th>User</th>
                    <th>Subject</th>
                    <th>Grade</th>
                    <th>Date</th>
                </thead>


<tbody>
    <?php

    if (count($records) > 0) {
        foreach($records as $record) {

            echo "<tr>
                      <td>".$record['id']."</td>
                      <td>".$record['User']."</td>
                      <td>".$record['name']."</td>
                      <td>".$record['grade']."</td>
                      <td>".$record['date']."</td>
                  </tr>";
        }

       }
    ?>

</tbody>

</body>
</html>
if($hasil > 0)
{

   $pelogin =$this->db->get_where('usuarios',array('username' => $user, 'password' => $pass))->row();
  // here $pelogin has the id of the user 
 // create session like this 
  $this->session->set_userdata(array('id' => $pelogin->id));
//  OR  like this 
// $this->session->set_userdata('id', $pelogin->id);

  if($pelogin ->type == 0)
  {
    // here goes  the admin data 
     redirect('admin');
  }

  else{
           //call here usuario method which has user data who logged in like
             redirect('usuario');
          // OR
          // Call some method which has user data in $records and 
      }
}

身份证件
使用者
主题
等级
日期

如果用户类型为admin,则会转到admin页面;如果用户类型为normal,则会转到user页面及其所有数据。当用户类型不是admin时,您不发送任何用户数据。之所以生成此通知,是因为当用户不是管理员时,$records在usuario页面不可用 在具有相应数据的控制器中为admin和usuario方法创建admin方法

您的登录控制器: 添加这些方法

 // for admin data 
 public function admin (){

  $data['records']=$this->m_login->getDetails();
  $this->load->view('admin_view_page',$data);
}
// for user data 
public function usuario(){

    $data['records']=$this->m_login->getDetails();
    $this->load->view('usuario',$data);
}
修改
do\u登录
方法如下:

        </head>

        <body>
            <div class="container">
            <h3>Login</h3>
            <hr>
            <form action="<?php echo base_url('login/do_login')?>" method="POST">
                <div class="form-group">
                    <label for="cari">USERNAME</label>
                    <input type="text" name="usuario" id="usuario" class="form-control">

                </div>

                <div class="form-group">
                    <label for="cari">PASSWORD</label>
                    <input type="password" name="contrasena" id="contrasena" class="form-control">

                </div>

                <input class="btn btn-primary" type="submit" value="Login" name="login">
                <input class="btn btn-primary" type="reset" value="Reset">

            </form>
                </div>



        </body>
</html>
    <?php

        Class Login extends CI_Controller{


        public function index(){


           $this->load->view('login_form');


        }

 public function do_login()
        {
         // load the form_validation library
         $this->load->library('form_validation');

         $this->form_validation->set_rules('usuario', 'Username', 'trim|required|min_length[3]|alpha_numeric');
         $this->form_validation->set_rules('contrasena', 'Password', 'trim|required|min_length[6]');

           // if there is errors
         if ($this->form_validation->run() == FALSE) { 
            // this will load your form with the errors

               $this->load->view('login_form'); 

         } else {
           // if no errors we will hit the database
            $user=$this->input->post('usuario', true);
            $pass=$this->input->post('contrasena', true);
            $cek = $this->m_login->proceso_login($user,$pass);
            $hasil=count($cek);

            if($hasil > 0){

                $pelogin =$this->db->get_where('usuarios',array('username' => $user, 'password' => $pass))->row();

                if($pelogin ->type == 0){
                    redirect('login/admin');
                }

                else{
                    redirect('login/usuario');
                }
            }
            redirect('login/index');
        }
    }


            public function home(){

                $data['records']=$this->m_login->getDetails();
                $this->load->view('usuario',$data);
            }
        public function getDetails()
        {
            $st=$this->db->SELECT('cursadas.*, usuarios.name as usuarios, materias.name as materias_name')->from('cursadas')
                ->join('usuarios','usuarios.id=cursadas.user_id')
                ->join('materias','materias.id=cursadas.subject_id')
                ->WHERE('cursadas.user_id=',$this->session->userdata['id'])
                ->get()->result_array();
            return $st[0]; // or use the row function
        }
                <table class="table table-hover" align="center" border="1" cellspacing="0" cellpadding="0" width="700" id="tabla_busqueda">
                <thead>
                    <th>id</th>
                    <th>User</th>
                    <th>Subject</th>
                    <th>Grade</th>
                    <th>Date</th>
                </thead>


<tbody>
    <?php

    if (count($records) > 0) {
        foreach($records as $record) {

            echo "<tr>
                      <td>".$record['id']."</td>
                      <td>".$record['User']."</td>
                      <td>".$record['name']."</td>
                      <td>".$record['grade']."</td>
                      <td>".$record['date']."</td>
                  </tr>";
        }

       }
    ?>

</tbody>

</body>
</html>
if($hasil > 0)
{

   $pelogin =$this->db->get_where('usuarios',array('username' => $user, 'password' => $pass))->row();
  // here $pelogin has the id of the user 
 // create session like this 
  $this->session->set_userdata(array('id' => $pelogin->id));
//  OR  like this 
// $this->session->set_userdata('id', $pelogin->id);

  if($pelogin ->type == 0)
  {
    // here goes  the admin data 
     redirect('admin');
  }

  else{
           //call here usuario method which has user data who logged in like
             redirect('usuario');
          // OR
          // Call some method which has user data in $records and 
      }
}

您在视图中有变量
$records
,但在控制器上没有

改变

$data['record'] = $this->m_login->getDetails();

另一种方法是在控制器上

查看usuario.php

<?php if ($records) {?>
<?php foreach($records as $record) {?>
<tr>
<td><?php echo $record['id'];?></td>
<td><?php echo $record['User'];?></td>
<td><?php echo $record['name'];?></td>
<td><?php echo $record['grade'];?></td>
<td><?php echo $record['date'];?></td>
</tr>
<?php } ?>
<?php } else { ?>
<tr> 
<td>No Results Found</td>
</tr>
<?php } ?>

未找到任何结果
仅举一个使用php哈希的示例 提示不要将计划密码存储在dbvarchar的数据库哈希密码列中 255


问问自己,
$records
在传递到和查看之前,如何以及在何处分配值?我是否已尽我所能确保分配的值有效?伙计,也许我有点头晕,但我不明白,问题出在哪里:/@DFriend可以帮我解决吗?:S:(,出现了什么dude?抱歉,还有其他事情要做。请确保您从模型中获得了良好的数据。换句话说,
$st[0]
是您所需要的吗?但是您没有添加admin/usuario函数dude:S。那怎么办?dude,我应该在哪里输出这个?:>另一种方法是在控制器上$results=$this->m_login->getDetails();$data['records']=array();if($results){foreach($results as$result){$data['records'][]=array('id'=>$result['id'],'User'=>$result['User'],'name'=>$result['name'],'grade'=>$result['grade'],'date'=>$result['date']))}$this->load->view('usuario',$data);在你的主页功能中,我重新编辑了它。还有登录示例我发誓,你帮了我很多。你实现了很多,非常感谢。但是我不明白,我的程序工作不正常,我尝试过,但不知道如何修改查询:/看一看: