我回来了另一个问题:(。我正在尝试创建我的登录功能,但由于某种原因它不会触发。我已经盯着代码两个小时了,似乎无法找到问题。我得到的结果只是一个空白页面@ http://localhost:8888/core/login_wax
。那就是我点击Log In!
按钮@ http://localhost:8888/core
。我希望至少有一个人会发现问题告诉我。我真的很感谢我得到的所有帮助。谢谢。
在数据库中,我有一个名为users
的表,其中有4行id
,name
,password
和email
。
控制器 - 核心
<?php
class Core extends CI_Controller {
public function __construct() {
parent::__construct();
}
public function index() {
$data = array('loggedV' => 'false');
$this->load->view('core_v', $data);
}
public function login_wax() {
$name = $this->input->post('login_name_field');
$password = $this->input->post('login_pw_field');
$this->do_login($name, $password);
}
private function do_login($name, $password)
{
$this->load->model('User_m');
$user_id = $this->User_m->get_user($name, $password);
/* If user has been found */
if($user_id) {
$this->session->set_userdata('user_id', $user_id);
/* Query that retrievs users name and assigns it to $user_name */
$user_name = "James";
$data = array('logged' => 'true', 'name' => $user_name);
$this->load->view('core_v', $data);
/* If user has NOT been found in the DB */
} else {
/* Tell him the name or pw are wrong */
$message = "Wrong Input";
}
}
模型 - 用户
<?php
class User_m extends CI_Model {
public function get_user($name, $password) {
$query = $this->db->query("SELECT * FROM (`users`) WHERE `name` = \"$name\" AND `password` = \"$password\" LIMIT 1");
if ($query->num_rows() > 0)
{
$row = $query->row();
return $row->id;
}
return false;
}
}
查看 - 核心
<?php echo form_open('core/login_wax'); ?>
<input type="text" class="n_reset" name="login_name_field" id="name" value="Mail / Email"></input>
<input type="password" name="login_pw_field" value="password" class="p_reset" id="password">
<input type="submit" id="whatever" name="whatever" value="Log In!">
</form>
答案 0 :(得分:0)
$this->load->model('User_m');
$user_id = $this->User_m->get_user($name, $password);
这应该是
$this->load->model('user_m');
$user_id = $this->user_m->get_user($name, $password);
答案 1 :(得分:0)
以下是您目前在代码中出现的错误:
使用
$this->load->helper('form');
之后在你的控制器中
parent::__construct();
但是这样可以解决这个问题 - 你需要看到错误。
确保您的环境在主index.php文件中设置为“development”。 确保您的php.ini设置为display_errors = On
确保在编写无效代码时,肯定会显示PHP错误
编辑: 在do_login()函数中,当身份验证失败时,您不会显示任何内容:
$message = "Wrong Input";
下面放
echo $message;