我在笨只是新的,我有這個錯誤我有一個錯誤在我的__construct
一個PHP錯誤遇到
嚴重性:注意
消息:未定義的屬性:stdClass的:: $ DATA
文件名:驅動器/ Session_database_driver.php
行號:171
回溯:
文件: C:\ Apache24 \ htdocs中\ iCareFinal \應用\控制器\的welcome.php 線:20功能:__construct
文件:C:\ Apache24 \ htdocs中\ iCareFinal \的index.php線:292功能: require_once
這裏是我的控制器的welcome.php
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class Welcome extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('login/m_login');
$this->load->library(array('form_validation','session'));
$this->load->database();
$this->load->helper('url');
}
public function index()
{
$session = $this->session->userdata('isLogin');
if($session == FALSE)
{
redirect('welcome/login_form');
}
else
{
redirect('home');
}
}
public function login_form()
{
$this->form_validation->set_rules('username', 'Username', 'required|trim|xss_clean');
$this->form_validation->set_rules('password', 'Password', 'required|md5|xss_clean');
$this->form_validation->set_error_delimiters('<span class="error">', '</span>');
if($this->form_validation->run()==FALSE)
{
$this->load->model('select');
$user=$this->select->getid();
$this->load->view('include/loginpage/header');
$this->load->view('loginView/loginPage');
$this->load->view('include/loginpage/footer');
}else
{
$username = $this->input->post('username');
$password = $this->input->post('password');
$cek = $this->m_login->takeUser($username, $password);
if($cek <> 0)
{
$this->session->set_userdata('isLogin', TRUE);
$this->session->set_userdata('username',$username);
// save data to a session
$user_id = 199911019;
$newdata = array(
'user_id' => $user_id
);
$this->session->set_userdata($newdata);
redirect('home');
}else
{
echo " <script>
alert('Failed Login: Check your username and password! $password');
history.go(-1);
</script>";
}
}
}
public function logout()
{
$this->session->sess_destroy();
redirect('welcome/login_form');
}
}
型號m_login.php
<?php
if(!defined('BASEPATH')) exit('Hacking Attempt : Get Out of the system ..!');
class M_login extends CI_Model
{
public function __construct()
{
parent::__construct();
}
public function takeUser($username, $password)
{
$this->db->select('*');
$this->db->from('USERS');
$this->db->where('USERNAME', $username);
$this->db->where('PASSWORD', $password);
$query = $this->db->get();
return $query->num_rows();
}
public function userData($username)
{
$this->db->select('username');
$this->db->select('name');
$this->db->where('username', $username);
$query = $this->db->get('USERS');
return $query->row();
}
}
查看loginPage.php
<body>
<div>
<div class="welcome">
<h4 class="text-muted mt-0 font-alt" style="font-size: 20px; font-family: 'Times New Roman', Times, serif;" >Welcome to myADNU</h4>
</div>
<hr class="hr-width">
<form action="<?php echo site_url('Welcome/index'); ?>" method="post">
<div id="bootstrap-tagsinput" class="form-group has-feedback">
<input type="text" class="form-control" placeholder="ID Number" name="username" />
<i class="glyphicon glyphicon-user form-control-feedback"></i>
</div>
<br>
<div id="bootstrap-tagsinput" class="form-group has-feedback">
<input type="password" class="form-control" placeholder="Password" name="password" />
<i class="glyphicon glyphicon-lock form-control-feedback"></i>
</div>
<br>
<div id="bootstrap-tagsinput">
<button type="submit" class="btn btn-primary btn-lg btn-block">SUBMIT</button>
</div>
</form>
</div>
</div><!-- /.container -->
這裏是我的會話表名CI_SESSION DATA VARCHAR2(500字節)ID VARCHAR2(200字節)IP_ADDRESS VARCHAR2(20 BYTE)TIMESTAMP NUMBER(20,0)
請他LP。謝謝
查看下面的代碼.. –
只是一個想法,我會自動加載數據庫在autoload.php文件也在您的視圖中您的site_url()在表單行動改變爲base_url() – user4419336
@vhann你檢查下面的代碼? –