[eluser]Unknown[/eluser]
Hi Guys!
I got that error, when i'm trying to add a new user to db.
A PHP Error was encountered
Severity: Notice
Message: Undefined offset: 1
Filename: libraries/Form_validation.php
Line Number: 953
A Database Error Occurred
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE ` = 'testuser' LIMIT 1' at line 2
SELECT * WHERE ` = 'testuser' LIMIT 1
Filename: E:\xampp\htdocs\codeigniter\emagshop\system\database\DB_driver.php
Line Number: 330
Before this, i could add a user, but only without 'is_required', so i was added multiple same users.
After I added this rule, i got that error and also can't login with a live user+pass.. Just nothing happened.. no error, no any kind of message.
model:
Code:
<?php //if ( ! defined('BASEPATH')) exit('Direkt hozzáférés nem megengedett!');
class User_model extends CI_Model {
public function __construct()
{
parent::__construct();
// $this->load->library('database');
$this->load->library('session');
$this->load->helper('url');
}
function login($email,$password)
{
$this->db->where("email",$email);
$this->db->where("password",$password);
$query=$this->db->get("user");
if($query->num_rows()>0)
{
foreach($query->result() as $rows)
{
//add all data to session
$newdata = array(
'user_id' => $rows->id,
'user_name' => $rows->username,
'user_email' => $rows->email,
'logged_in' => TRUE,
);
}
$this->session->set_userdata($newdata);
return true;
}
return false;
}
public function add_user()
{
$data=array(
'username'=>$this->input->post('user_name'),
'email'=>$this->input->post('email_address'),
'password'=>md5($this->input->post('password'))
);
$this->db->insert('user',$data);
}
}
?>
controller:
[code]<?php if ( ! defined('BASEPATH')) exit('Direkt hozzáférés nem megengedett!');
class User extends CI_Controller{
public function __construct()
{
parent::__construct();
$this->load->model('user_model');
$this->load->helper('form');
}
public function index()
{
if(($this->session->userdata('user_name')!=""))
{
$this->welcome();
}
else{
$data['title']= 'Regisztráció';
$this->load->view('templates/header',$data);
$this->load->view("user/registration_view.php", $data);
$this->load->view('templates/footer',$data);
}
}
public function welcome()
{
$data['title']= 'Üdvözöljük';
$this->load->view('templates/header',$data);
$this->load->view('user/welcome_view.php', $data);
$this->load->view('templates/footer',$data);
}
public function login()
{
$email=$this->input->post('email');
$password=md5($this->input->post('pass'));
$result=$this->user_model->login($email,$password);
if($result) $this->welcome();
else $this->index();
}
public function thank()
{
$data['title']= 'Köszönjük';
$this->load->view('templates/header',$data);
$this->load->view('user/thank_view.php', $data);
$this->load->view('templates/footer',$data);
}
public function registration()
{
$this->load->library('form_validation');
// field name, error message, validation rules
// user login
$this->form_validation->set_rules('user_name', 'User Name', 'trim|required|min_length[4]|xss_clean|is_unique');
$this->form_validation->set_rules('email_address', 'Your Email', 'trim|required|valid_email|is_unique');
$this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[4]|max_length[32]');
$this->form_validation->set_rules('con_password', 'Password Confirmation', 'trim|required|matches[password]');
if($this->form_validation->run() == FALSE)
{
$this->index();
}
else
{
$this->user_model->add_user();
$this->thank();
}
}
public function logout()
{
$newdata = array(
'user_id' =>'',
'user_name' =>'',
'user_email' => '',
'logged_in' => FALSE,
);
$this->session->unset_userdata($newdata );
$this->session->sess_destroy();
$this->index();
}
}
?>
Don't know is the a bug or i did something bad.. :S
Thanks for the reply,
Best regards,
K.