How to Edit data? Simple question |
Hello everyone! I have a simple question about editing data in CI.
I have a simple view, with link to edit a record, like this: PHP Code: <?php echo site_url("edit/person/".$item['id']) ;?> where 'id' is user ID in a database. On this View, I have a form: PHP Code: <?php echo form_open('edit/person'); ?> There is my Edit method: PHP Code: public function person($id=NULL) And my model has 'person_edit()' method. This code is working fine and updates the data, but if I try to submit form with blank 'username' field, I get an error because PHP Code: $this->load->view('detail', $data); in my Edit method doesn't have parameter for ID. How can I put the GET ID parameter in a load-view? thanks Sorry for a noob question...
Your getting the error because you are using a set_rule on the username field.
If your editing a record you do not need the set_rule for the username. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
Not working. I think I getting the error because there is no ID in GET parameter, after I clear "username" field and click "submit" button.
my "edit" method, id is "hidden" form field: PHP Code: public function person_edit()
See https://www.codeigniter.com/user_guide/d...er::update
Your Code: $this->db->update('users', $data,$wh); Instead, add the id to the data array: Code: $data = array(
Not working. Update method is working fine, if the "username" field is not empty. Hm... Let's watch an example: I have a link http://localhost/it/index.php/edit/person/28, where "28" is person ID in database. If "username" field is not empty, update method correctly update table for user_id 28. If I try to submit form with empty "username" field, I have a link http://localhost/it/index.php/edit/person/, without ID parameter. ID is needed to get data from database. That's why I have en error.
How can I add ID parameter to the view, after I click "submit" button? And my route after submitting form http://localhost/it/index.php/edit/person/28, not http://localhost/it/index.php/edit/person
Then you will need to check if the username is empty or not.
PHP Code: $data = array( Other wise you are passing the person_name to the database as empty. A better way of doing this would be to fill in all of the form fields on an edit then allow them to change the fields. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
|
Welcome Guest, Not a member yet? Register Sign In |