• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to insert corporate details into database

#1
Firstly, I dont use a database very much but do find it necessary for storing members info & for logging in.

Now, I want to store corporate info & again for the corporate personnel to log in, just the same as we do in real life.

I have a Controller & view that creates folders for each corporation, and later intending the same for each country, and that works good. I just want to store the Corporates Name, Password, and Country into the database, and then be able to log in, just the same as a member logs in.

I have created a separate table, tbl_corporates, in the database with 5 columns (1) corporate_id (2) date_ registered (3) corporate_name (4) pass_word (5) country_territory

I guess the first 2 can be handled within the database.

I have created models for each country, the first being Afghanistancorporate_model. The coding within that model is as follows;

PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

class 
Afghanistancorporate_model extends CI_Model
{
    function 
__construct()
    {
    
parent::__construct();
    
$this->load->database();
    }

public function 
insert_corporate($corporatename$password$countryterritory)
    {
    
$data = array('corporate_name'=> $corporatename'pass_word'=> $password'country_territory'=> $countryterritory);
    
$this->db->insert('tbl_corporates'$data);
    }


Within the Controller I have the following;

PHP Code:
$this->load->model('Afghanistancorporate_model''afghanistancorporate_model');

$corporatename $this->input->post('corporatename');
$password $this->input->post('password');
$countryterritory $this->session->userdata('country_territory'); 

Ive tried putting the defined variables into the Model but that doesnt work. Ive also tried the $data = array in the Controller but that doesnt work.

I have searched many sites to find what Im doing wrong, but to no avail. Can anybody help?
Reply

#2
PHP Code:
$this->Afghanistancorporate_model->insert_corporate($corporatename$password$countryterritory); 

Place that after all your inputs.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#3
(11-16-2020, 12:39 PM)InsiteFX Wrote:
PHP Code:
$this->Afghanistancorporate_model->insert_corporate($corporatename$password$countryterritory); 

Place that after all your inputs.

Thanks InsiteFX. To be certain that I understand you correctly, this is what I changed to.

PHP Code:
public function insert_corporate($corporatename$password$countryterritory)
    {
    
$data = array('corporate_name'=> $corporatename'pass_word'=> $password'country_territory'=> $countryterritory);
    
$this->db->insert('tbl_corporates'$data);
    
$this->Afghanistancorp_model->insert_corporate($corporatename$password$countryterritory);
    } 

But it didnt work.

Ive even tried inserting the same data into 3 spare columns I have in the members table but still didnt work.

Ive clicked on "create view" in the corporate table and get an error message saying .... "It seems that the connection to the server has been lost" ....

But I get the same message if I do the same in the members table. The members table must be connected otherwise it wouldnt log in.
Reply

#4
No, you want to do it in the controller.

Controller:

PHP Code:
$this->load->model('Afghanistancorporate_model''afghanistancorporate_model');

$corporatename $this->input->post('corporatename');
$password $this->input->post('password');
$countryterritory $this->session->userdata('country_territory'); 

$this->Afghanistancorporate_model->insert_corporate($corporatename$password$countryterritory); 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#5
(11-17-2020, 12:05 PM)InsiteFX Wrote: No, you want to do it in the controller.

Controller:

PHP Code:
$this->load->model('Afghanistancorporate_model''afghanistancorporate_model');

$corporatename $this->input->post('corporatename');
$password $this->input->post('password');
$countryterritory $this->session->userdata('country_territory'); 

$this->Afghanistancorporate_model->insert_corporate($corporatename$password$countryterritory); 

Thanks InsiteFX. I already have the first 4 lines in the Controller. If I put the fifth line in the Controller, after the variable definitions, I get error;

Message: Undefined property: Afghanistan::$Afghanistancorporate_model

Ive moved it to several different places in the Controller & tried it surrounded by curly brackets but still did not enter the corporate table.

The fifth line has been deleted from the model.

Im exhausted with ideas, other than trying again to enter it into the members table.
Reply

#6
My fault, in your model you gave it an alias name which had a lower case first letter try this now.

PHP Code:
$this->load->model('Afghanistancorporate_model''afghanistancorporate_model');

$corporatename $this->input->post('corporatename');
$password $this->input->post('password');
$countryterritory $this->session->userdata('country_territory'); 

$this->afghanistancorporate_model->insert_corporate($corporatename$password$countryterritory); 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#7
(11-18-2020, 07:48 AM)InsiteFX Wrote: My fault, in your model you gave it an alias name which had a lower case first letter try this now.

PHP Code:
$this->load->model('Afghanistancorporate_model''afghanistancorporate_model');

$corporatename $this->input->post('corporatename');
$password $this->input->post('password');
$countryterritory $this->session->userdata('country_territory'); 

$this->afghanistancorporate_model->insert_corporate($corporatename$password$countryterritory); 

Yes, that fixed it. But I cant see where I used lower case first letter. The rules are that models must have upper case first letter.

Now I know how to insert into a database, I should be able to resolve my other problem of uploading photos & fwrite data for an advert. If I upload the photos first & insert $product into a temp field of a database table then redirect (that Im still working on) to the data upload and recover the $product name by;

PHP Code:
$product $this->session->userdata('temp_1'); 

But then I will need to delete the contents of that field probably best when it redirects to the finished advert.

Do you know how to delete the contents?

Im jumping the gun here a little coz I should be searching before I ask questions. I hope you dont mind.

UPDATE

I think I can answer my question as follows. Just correct me if they are wrong.

These go into a model;

PHP Code:
public function insert_product($product)
    {
    
$data = array('temp_1'=> $product);
    
$this->db->insert('tbl_members'$data);
    }

public function 
delete_product($product)
    {
    
$data = array('temp_1'=> $product);
    
$this->db->delete('tbl_members'$data);
    } 

And these go into the appropriate Controllers;

PHP Code:
$this->members_model->insert_product($product);
$this->members_model->delete_product($product); 
Reply

#8
You used and alias when you initiated your model.

PHP Code:
---------------------> Model -----------------------> Model Alias Name.
$this->load->model('Afghanistancorporate_model''afghanistancorporate_model'); 

You only need the first one the alias is if you want to use a different name for your model.

Yes that is the correct way of doing it.

On your model calls you can assigning a result from the insert and delete.
All the model methods and QueryBuilder return a result from the methods.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#9
(11-18-2020, 12:30 PM)InsiteFX Wrote: You used and alias when you initiated your model.

PHP Code:
---------------------> Model -----------------------> Model Alias Name.
$this->load->model('Afghanistancorporate_model''afghanistancorporate_model'); 

You only need the first one the alias is if you want to use a different name for your model.

Yes that is the correct way of doing it.

On your model calls you can assigning a result from the insert and delete.
All the model methods and QueryBuilder return a result from the methods.

OK, Im still struggling with the redirect after uploading photos. In the corporate listing, which includes uploading a document, that redirects with no problem, but the photo uploads will not redirect properly. Ive even taken the corporate listing coding and alongside put the photo uploads but still can not find a solution. I put that model coding inside but it didnt work. I'll keep working on it, so maybe back later with other questions.
Reply

#10
(11-18-2020, 12:30 PM)InsiteFX Wrote: You used and alias when you initiated your model.

PHP Code:
---------------------> Model -----------------------> Model Alias Name.
$this->load->model('Afghanistancorporate_model''afghanistancorporate_model'); 

You only need the first one the alias is if you want to use a different name for your model.

Yes that is the correct way of doing it.

On your model calls you can assigning a result from the insert and delete.
All the model methods and QueryBuilder return a result from the methods.

Im almost at the my destination. But cant get the $product to enter temp_1

The first line of this coding is in the Controller and other lines in the Model;

PHP Code:
    $this->username_model->update_product($product);

public function 
update_product($product)
    {
    
$this->db->where('user_name'$lcuser);
    
$data = array('temp_1'=> $product);
    
$this->db->update('tbl_members'$data);
    } 

If I use "insert" it creates a new line & I dont want that. Im assuming I wont need delete coz a new entry should replace the old.

What can be wrong with the above?
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.