CodeIgniter Forums
[SOLVED] can't save transaction without details - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: [SOLVED] can't save transaction without details (/showthread.php?tid=27165)

Pages: 1 2 3 4 5 6 7 8 9 10 11


[SOLVED] can't save transaction without details - El Forum - 02-07-2010

[eluser]theprodigy[/eluser]
Quote:case $crudConfig['create']:

print_r($_POST);
$id = $this->input->post("id"); <------ This is NULL as shown in your print_r
$data['id'] = $this->User->savecompany_details($id); <------ You are passing NULL to your function
}
break;
Quote:function savecompany_details($id)
{

$data['company_id'] = $id;
$this->db->insert('maint_company', $data); <------ You are inputting a NULL value to your database
<------ You aren't returning anything to send back to populate $data['id']

}



[SOLVED] can't save transaction without details - El Forum - 02-08-2010

[eluser]maria clara[/eluser]
[quote author="theprodigy" date="1265629022"]
Quote:case $crudConfig['create']:

print_r($_POST);
$id = $this->input->post("id"); <------ This is NULL as shown in your print_r
$data['id'] = $this->User->savecompany_details($id); <------ You are passing NULL to your function
}
break;
Quote:function savecompany_details($id)
{

$data['company_id'] = $id;
$this->db->insert('maint_company', $data); <------ You are inputting a NULL value to your database
<------ You aren't returning anything to send back to populate $data['id']

}
[/quote]

yeah, i thought so.. but when i put return $id; in my savecompan_details() function it doesn't have any changes. i figuring where i gone wrong???


[SOLVED] can't save transaction without details - El Forum - 02-08-2010

[eluser]theprodigy[/eluser]
Code:
function savecompany_details($id)
{
    $data[‘company_id’] = $id;
    $this->db->insert(‘maint_company’, $data);

    return $this->db->insert_id();           // <------ return the insert id (the id created when the record was inserted)
  }

but, you are going to have a hard time getting one, with trying to insert a null record (unless every field in your database is set to allow null - other then the id which is auto incremented)


[SOLVED] can't save transaction without details - El Forum - 02-08-2010

[eluser]maria clara[/eluser]
[quote author="theprodigy" date="1265630891"]
Code:
function savecompany_details($id)
{
    $data[‘company_id’] = $id;
    $this->db->insert(‘maint_company’, $data);

    return $this->db->insert_id();           // <------ return the insert id (the id created when the record was inserted)
  }

but, you are going to have a hard time getting one, with trying to insert a null record (unless every field in your database is set to allow null - other then the id which is auto incremented)[/quote]

i have tried and put the code as you said and i notice something in the console

Quote:Array
(
[company_code] => fdsfsd
[company_name] => fsdfsdf
[id] => _empty
[oper] => add
)
{"id":21} <------------now the value of the id is 21 but it don't post

is it now adding?? i looked at the structure of my db table maint_company and noticed that it doesn't have allowing a null value in every field.


[SOLVED] can't save transaction without details - El Forum - 02-08-2010

[eluser]theprodigy[/eluser]
the way to see if it's adding is to check the database records, not the database structure.

To get the information posted to be inserted into the database, you need to pass the information to your savecompany_details method.
There is no need to pass the id, as it will be empty at the time of passing the info. Just pass the other info

Code:
case $crudConfig['create']:

                //print_r($_POST);          <----- no longer need this
                $data['company_code'] => $this->input->post('company_code');
                $data['company_name'] => $this->input->post('company_name');

                $data['id'] = $this->User->savecompany_details($data);
                }
                break;

Code:
function savecompany_details($id)
{
    $this->db->insert(‘maint_company’, $data);

    return $this->db->insert_id();
}



[SOLVED] can't save transaction without details - El Forum - 02-08-2010

[eluser]maria clara[/eluser]
it shows me a parse error like this
Quote:Parse error: parse error in C:\xampp\htdocs\comunion\system\application\modules\sec_users\controllers\sec_users.php on line 554

every time i commented this block of codes:
Code:
case $crudConfig['create']:
                /*$c = "";
                $id['company_code'] = $this->input->post('company_code');
                $sec_exist = $this->User->getCompanyDetails($id);
                
                if ($sec_exist)
                {
                    $c .= 'Company ID already exists.';
                    $data['action'] = 'exist';
                }
                else
                {
                $fields = array(
                        "company_code"
                        ,"company_name"
                        );
                
                foreach ($fields as $field)
                {if (isset($_POST[$field])) $id[$field] = $this->input->post($field);}*/

                $data['company_code'] => $this->input->post('company_code');
                $data['company_name'] => $this->input->post('company_name');

                $data['id'] = $this->User->savecompany_details($data);
                
                }
                break;

the commented block of code shows me a parse error. but when i uncommented it it works well but still don't show the data im adding.


[SOLVED] can't save transaction without details - El Forum - 02-08-2010

[eluser]theprodigy[/eluser]
Code:
case $crudConfig['create']:
                $c = "";
                $id['company_code'] = $this->input->post('company_code');
                $sec_exist = $this->User->getCompanyDetails($id);
                
                if ($sec_exist)
                {
                    $c .= 'Company ID already exists.';
                    $data['action'] = 'exist';
                }
                else
                {
                    $fields = array(
                        "company_code"
                        ,"company_name"
                    );
                
                foreach ($fields as $field)
                {
                    if (isset($_POST[$field]))
                    {
                        $data[$field] = $this->input->post($field);
                    }
                }

                $data['id'] = $this->User->savecompany_details($data);
                
                }
                break;



[SOLVED] can't save transaction without details - El Forum - 02-08-2010

[eluser]maria clara[/eluser]
it has a parse error and it pertains to your script at this line:

Quote:Parse error: parse error in C:\xampp\htdocs\comunion\system\application\modules\sec_users\controllers\sec_users.php on line 566

Code:
if (isset($_POST[$field]))
                    {
                        $data[$field] = $this->input->post($field);
                    }
<----- this is the line 566


[SOLVED] can't save transaction without details - El Forum - 02-08-2010

[eluser]theprodigy[/eluser]
Quote:it has a parse error and it pertains to your script at this line:

Quote:Parse error: parse error in C:\xampp\htdocs\comunion\system\application\modules\sec_users\controllers\sec_users.php on line 566

if (isset($_POST[$field]))
{
$data[$field] = $this->input->post($field);
}

that's actually your script. I just reformatted it. It's the same script as

Quote:{if (isset($_POST[$field])) $id[$field] = $this->input->post($field);}

Try changing your entire else block to something like:

Code:
else
{
    if($this->input->post('company_code'))
    {
        $data['company_code'] = $this->input->post('company_code');
    }
    if($this->input->post('company_name'))
    {
        $data['company_name'] = $this->input->post('company_name');
    }

    $data['id'] = $this->User->savecompany_details($data);
                
}



[SOLVED] can't save transaction without details - El Forum - 02-08-2010

[eluser]maria clara[/eluser]
i have changed my code and still trying to update it to solve my problem..

here's my controller:
Code:
case $crudConfig['create']:
                $c = "";
                $id['company_code'] = $this->input->post('company_code');
                $sec_exist = $this->User->getCompanyDetails($id);
                
                if ($sec_exist)
                {
                    $c .= 'Company ID already exists.';
                    $data['action'] = 'exist';
                }
                else
                {
                $fields = array(
                        "company_code"
                        ,"company_name"
                        );
                
                foreach ($fields as $field)
                {if (isset($_POST[$field])) $id[$field] = $this->input->post($field);}

                //print_r($_POST);
                $item = $this->input->post("item");        
                $data['item'] = $this->User->savecompany_details($id);
                }
                break;

here's my model:

Code:
function savecompany_details($id) //Query for saving the company
    {
    
        $data['company_id'] = $id;
        $this->db->insert('maint_company',$id);
        
        return $this->db->insert_id();        
        
    }

i think its already adding but it just don't posting the value of the item. because i have this:

Quote:Array
(
[company_code] => fhfghf
[company_name] => hgfhfgh
[id] => _empty
[oper] => add
)
{"item":33} <--------------------------- item is equal to the id of data being added