[eluser]linusan[/eluser]
Update 2: I've solved the problem. It think I did wrong by passing two arrays to the where function.
Hi, I'm new to Codeigniter and trying to build a function which changes (updates) the usernames of members. I've read the user guide at least 10 times and searched the forums but can't get it working.
I'm trying to grab the current username from the users session (the login function saves the name into the session array) und pass it to the db->update function. At the same time I'm trying to pass a POST from a form (where the new username has been entered) to the query as well. Then the session username gets changed as well, this seems to work... at least one thing :-) I've set the whole thing into a function which checks if the whole update worked and it returns yes.. so there is no error message at all. Maybe I've messed up the syntax order in the db->update statement?
Here is my controller code:
Code:
function validateName(){
$new = array(
'u_name' => $this->input->post('u_name')
);
$all = $this->session->all_userdata();
$where = array(
'u_name' => $all['u_name']
);
$this->load->library('form_validation');
$this->form_validation->set_rules('u_name', 'Name', 'trim|min_length[4]');
if($this->form_validation->run() == FALSE) {
redirect('settings/show');
} else {
$this->load->model('changename_model');
if($query = $this->changename_model->changename($new)) {
//redirect('settings/show');
echo 'ok';
} else {
//redirect('settings/show');
echo 'not ok';
}
}
Here comes the model:
Code:
function changename($new){
$new = array(
'u_name' => $this->input->post('u_name')
);
$all = $this->session->all_userdata();
$where = array(
'u_name' => $all['u_name']
);
$this->db->where('u_name', $where);
$update = $this->db->update('users', $new);
return $update;
$this->session->set_userdata($new);
redirect('settings/show');
}
Thanks a lot!
Update: I've found an typo where I loaded the model. Now I'm getting an error message but can't figure out to solve it:
Quote:A Database Error Occurred
Error Number: 1054
Unknown column 'Niko' in 'where clause'
UPDATE `users` SET `Nikolaj` = '' WHERE `u_name` = 'Nikolaj' AND `Niko` IS NULL
Filename: /htdocs/findjou/models/changename_model.php
Line Number: 20