Jakebert Posted December 11, 2009 Share Posted December 11, 2009 Here's my problem, I hope someone can help me see the error! When I go to edit a student, the information comes up in the form fine. When I try to submit the form I get three PHP Notices: A PHP Error was encountered Severity: Warning Message: Missing argument 1 for Students::edit() Filename: admin/students.php Line Number: 72 A PHP Error was encountered Severity: Notice Message: Undefined variable: sid Filename: admin/students.php Line Number: 94 A PHP Error was encountered Severity: Notice Message: Undefined variable: sid Filename: admin/students.php Line Number: 97 Those are all in the controller. Here is the relevant code (sorry that there's so much ) This is the index page (controller): function manage() { $data = $this->students->students(); // List the students $this->table->set_heading('ID', 'First', 'Last', 'Age', 'Gender', 'Level'); //Setting headings for the table foreach($data as $value => $key) { //Build action links $actions = anchor("admin/students/edit/".$key['sid']."/", "Edit") . anchor("admin/students/delete/".$key['sid']."/", "Delete"); //Adding row to table $this->table->add_row($key['sid'], $key['fname'], $key['lname'], $key['age'], $key['gender'], $key['level'], $actions); } $this->auth->view('students/manage'); // Load the view } Here's the edit controller (in students): function edit($sid) { $this->form_validation->set_rules('fname', 'First Name', 'trim|required'); $this->form_validation->set_rules('lname', 'Last Name', 'trim|required'); $this->form_validation->set_rules('age', 'Age', 'trim|required|numeric'); $this->form_validation->set_rules('gender', 'Gender', 'required'); $this->form_validation->set_rules('level', 'Level', 'trim|required'); if($this->form_validation->run() == FALSE) { $data = $this->students->fetch($sid); $this->auth->view('students/edit', $data[0]); } else { $data['fname'] = set_value('fname'); $data['lname'] = set_value('lname'); $data['age'] = set_value('age'); $data['gender'] = set_value('gender'); $data['level'] = set_value('level'); if ($this->students->edit($sid, $data)==1) {$this->auth->view('students/edit_success');} if($this->students->edit($sid,$data)==0) {echo 'There was an error with the update process. Sorry!';} and the data model: function fetch($sid) { $query = $this->db->get_where('students', array('sid' => $sid)); return $query->result_array(); } function edit($sid, $data) { $this->db->where('sid', $sid); $this->db->update('students', $data); return $this->db->affected_rows(); } and FINALLY the edit view: <fieldset> <legend>Personal Information</legend> <?php echo form_open('admin/students/edit'); ?> First Name: <?php echo form_input('fname', set_value('fname', $fname)); ?> Last Name: <?php echo form_input('lname', set_value('lname', $lname)); ?> <?php echo form_error('fname'); echo form_error('lname'); ?> <br /><br />Age: <?php echo form_input('age', set_value('age', $age)); ?> <?php echo form_error('age'); ?> <br /> <br /> Gender: <?php echo form_radio('gender', set_value('male', 'Male')); ?> Male <?php echo form_radio('gender', set_value('female', 'Female')); ?> Female <?php echo form_error('gender'); ?> </fieldset> <fieldset> <legend>Swimming Information</legend> Level: <?php echo form_input('level', set_value('level', $level)); echo form_error('level'); ?> </fieldset> <?php echo form_submit('submit', 'Edit Student'); echo form_close(); ?> Thank you for the help! Link to comment https://forums.phpfreaks.com/topic/184742-codeigniter-crud-issue/ Share on other sites More sharing options...
sKunKbad Posted December 13, 2009 Share Posted December 13, 2009 Your view's form open URL should contain the $sid after the edit URL segment. Link to comment https://forums.phpfreaks.com/topic/184742-codeigniter-crud-issue/#findComment-976380 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.