I am trying to save data into two different tables. One is Users and another is organisation.
Now i have form where i create a organisation in that form i have some fields that i want to store in users table.
The Fields that i want to store in users table are:
first_name,last_name,email,password
and i want to store the id of this inserted record in a variable called $sales_id.
So basically firstly i want to insert the data from form into users table then when i get the $sales_id after inserting users i want to proceed with inserting the data into organization table. So there i will use sales_id variable.
the Form is :
<form role="form" action="" method="post" class="registration-form">
<fieldset>
<div class="form-top">
<div class="form-top-left">
<h3>Step 1 / 3</h3>
<h3>Add A New Organization</h3>
</div>
<div class="form-top-right">
<i class="fa fa-user"></i>
</div>
</div>
<div class="form-bottom">
<div class="form-group">
<?php echo validation_errors(); ?>
<?php echo form_open(); ?>
<?php echo form_input('org_name', set_value('org_name', $company->org_name),'placeholder="Organization name..."',' class="form-first-name form-control"'); ?>
</div>
<div class="form-group">
<?php echo form_input('dba', set_value('dba', $company->dba),'placeholder="DBA"',' class="form-first-name form-control"'); ?>
</div>
<div class="form-group">
<?php echo form_input('city', set_value('city', $company->city),'placeholder="City"',' class="form-first-name form-control"'); ?>
</div>
<div class="form-group">
<?php echo form_input('pin', set_value('pin', $company->pin),'placeholder="Pin"',' class="form-first-name form-control"'); ?>
</div>
<div class="form-group">
<?php echo form_input('state', set_value('state', $company->state),'placeholder="State"',' class="form-first-name form-control"'); ?>
</div>
<div class="form-group">
<?php echo form_textarea('addr1', set_value('addr1', $company->addr1),'placeholder="Address"',' class="form-first-name form-control"'); ?>
</div>
<div class="form-group">
<?php echo form_textarea('addr2', set_value('addr2', $company->addr2),'placeholder="Address 2"',' class="form-first-name form-control"'); ?>
</div>
<button type="button" class="btn btn-next">Next</button>
</div>
</fieldset>
<fieldset>
<div class="form-top">
<div class="form-top-left">
<h3>Step 2 / 3</h3>
<h3>Set up your Sales account:</h3>
</div>
<div class="form-top-right">
<i class="fa fa-key"></i>
</div>
</div>
<div class="form-bottom">
<div class="form-group">
<?php echo form_input('first_name', set_value('first_name', $user->first_name),'placeholder="First name"',' class="form-first-name form-control"'); ?>
</div>
<div class="form-group">
<?php echo form_input('last_name', set_value('last_name', $user->last_name),'placeholder="Last Name"',' class="form-first-name form-control"'); ?>
</div>
<div class="form-group">
<?php echo form_input('email', set_value('email', $user->email),'placeholder="Email"',' class="form-first-name form-control"'); ?>
</div>
<div class="form-group">
<?php echo form_password('password', set_value('password', $user->password),'placeholder="Password"',' class="form-first-name form-control"'); ?>
</div>
<button type="button" class="btn btn-previous">Previous</button>
<button type="button" class="btn btn-next">Next</button>
</div>
</fieldset>
<fieldset>
<div class="form-top">
<div class="form-top-left">
<h3>Step 3 / 4</h3>
<h3>Set up your Technical account:</h3>
</div>
<div class="form-top-right">
<i class="fa fa-key"></i>
</div>
</div>
<div class="form-bottom">
<div class="form-group">
<?php echo form_input('first_name', set_value('first_name', $user->first_name),'placeholder="First name"',' class="form-first-name form-control"'); ?>
</div>
<div class="form-group">
<?php echo form_input('last_name', set_value('last_name', $user->last_name),'placeholder="Last Name"',' class="form-first-name form-control"'); ?>
</div>
<div class="form-group">
<?php echo form_input('email', set_value('email', $user->email),'placeholder="Email"',' class="form-first-name form-control"'); ?>
</div>
<div class="form-group">
<?php echo form_password('password', set_value('password', $user->password),'placeholder="Password"',' class="form-first-name form-control"'); ?>
</div>
<button type="button" class="btn btn-previous">Previous</button>
<button type="button" class="btn btn-next">Next</button>
</div>
</fieldset>
<fieldset>
<div class="form-top">
<div class="form-top-left">
<h3>Step 4 / 4</h3>
<p>Social media profiles:</p>
</div>
<div class="form-top-right">
<i class="fa fa-twitter"></i>
</div>
</div>
<div class="form-bottom">
<div class="form-group">
<?php echo form_input('tax_number', set_value('tax_number', $company->tax_number),'placeholder="Tax Number"',' class="form-first-name form-control"'); ?>
</div>
<div class="form-group">
<?php echo form_input('comment', set_value('comment', $company->comment),'placeholder="Comment"',' class="form-first-name form-control"'); ?>
</div>
<div class="form-group">
<?php echo form_input('url', set_value('url', $company->url),'placeholder="URL"',' class="form-first-name form-control"'); ?>
</div>
<button type="button" class="btn btn-previous">Previous</button>
<?php echo form_submit('submit', 'Save', 'class="btn btn-primary"','onClick="image()"'); ?>
<?php echo form_close();?>
</div>
</fieldset>
</form>
And the controller is:
public function add_company()
{
$this->data['company'] = $this->company_m->get_new();
$this->data['user'] = $this->secure_m->get_new();
//$rules = $this->company_m->rules_admin;
//$this->form_validation->set_rules($rules);
if ($this->form_validation->run() == TRUE)
{
$data = $this->company_m->array_from_post(array('org_name','dba','addr1','addr2','city','state','country','pin','sales_id','tech_id','tax_number','comment','url'));
$data_user = $this->user_m->array_from_post(array('first_name','last_name','email','password'));
$this->secure_m->save($data_user,$id);
$this->company_m->save($data, $id);
echo $this->db->last_query();
//redirect('admin/company');
}
// Load the view
$this->data['subview'] = 'admin/company/add';
$this->load->view('admin/_layout_main', $this->data);
}