Save image path to database / edit function not editing entry but inserting new one |
[eluser]ede196620[/eluser]
Hello everyone I am gonna try to kill two birds in one stone here by asking two questions. My first question is how to grab uploaded files name and store it in to a database i have the upload file function set up but cant find a way to save the path to a table. And my second question is about updating an entry in a database i have the function set up and was making some modifications to it and it stopped updating and instead it started creating new ones and i daunt know what i did for this to happen and cant revers the changes. This is still a work in progress. Any help is greatly appreciated here are the functions that are used in the process Code: // controller Code: public function get_new_product() { Code: public function array_from_post($fields) { Code: public function save($data, $id = NULL) {
[eluser]CroNiX[/eluser]
What's this? Code: $id = $filter($id); As far as getting the file path...it's containted in $this->upload->data(), which returns an array of attributes. See towards the bottom of http://ellislab.com/codeigniter/user-gui...ading.html You also misspelled update: Code: $this->db->updata($this->_table_name);
[eluser]ede196620[/eluser]
Hi CroNiX tnx for your replay I fixed the spelling error but same thing is happening and as for the Code: $id = $filter($id); this filters the id which is the primary key
[eluser]InsiteFX[/eluser]
Maybe this: Code: $this->db->updata($this->_table_name);
[eluser]InsiteFX[/eluser]
Do a echo var_dump($id); in your methods to see if your getting the id, if it never does the update then it's always inserting because $id is null.
[eluser]ede196620[/eluser]
well in the controller edit functions i did var_dump($id); and it returned an id that belongs to the selected item these are set in MY_Model and my product model Code: class MY_Model extends CI_Model { Code: lass Product extends MY_Model {
[eluser]Tim Brownlaw[/eluser]
You want to Check what $id where it's being used... See the added code... Code: public function save($data, $id = NULL) { You may have to add in an exit(); after the var_dump to stop it running to catch the output. And work back from there... Also it wouldn't hurt to do a var_dump of $data to ensure that is also correct... This is a case of "test" the different bits to make sure they are working, being passed the expected values... Don't guess!
[eluser]ede196620[/eluser]
sorry for the long wait i did a var_dump($id) and var_dump($data) the $id is not returning anything and the data dose return this array Code: array (size=8)
[eluser]InsiteFX[/eluser]
Where is $filter? You may need to add this: Code: $id = $this->filter($id); Also you did not show your input form, the problem could be there. If $id is null then it is not being passed from your form to your controller. |
Welcome Guest, Not a member yet? Register Sign In |