JayminsFakeAccount JayminsFakeAccount - 3 months ago 14
PHP Question

Same Function for editing and inserting In Codeigniter

OKay So I am developing Ecommerce website, where I am using Common View file for editing and inserting data. Issue is I have made a common function for adding and inserting too. So If we edit the form, It's Id is being passed in URL. The Function gets the URL and Manipulates the data and view edited form. Problem is for inserting the data. My Common Function accepts one parameter.[Id which is being passed when Editing]. It gives me error when I try to load 'Add File'.

Missing argument 1 for Register::product()

Here is my Code:

function product($get_product_id)
//DO Something
//Check POST data
// add OR UPDATE POST Data

View File:
<? if(isset($data))
foreach ($data as $data1)


<? echo form_open_multipart('register/product/'.$get_product_id.'');?>
<table width="90%" border="0" cellspacing="0" cellpadding="6">

<td width="20%" align="right"><? echo form_label('Product Name');?></td>
<td width="80%"><?echo form_input(array('id' =>'product_name','name' =>'product_name','size' => '64','value' => $get_product_name));echo form_hidden('id', $get_product_id);?>
//And So on...


Your controller code should be

   function product($get_product_id = NULL) {
    if ($get_product_id) {
        //edit code
    } else {
        //insert code

    //DO Something
    //Check POST data
    // add OR UPDATE POST Data