Welcome Guest, Not a member yet? Register   Sign In
How to insert corporate details into database
#11

Insert creates a new database record, update will update an existing record.

Delete will delete the record, replace will delete the record then insert it.


PHP Code:
$data = [
        'title' => 'My title',
        'name'  => 'My Name',
        'date'  => 'My date'
];

$builder->replace($data);

// Executes: REPLACE INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date') 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#12

(11-20-2020, 04:31 PM)InsiteFX Wrote: Insert creates a new database record, update will update an existing record.

Delete will delete the record, replace will delete the record then insert it.


PHP Code:
$data = [
        'title' => 'My title',
        'name'  => 'My Name',
        'date'  => 'My date'
];

$builder->replace($data);

// Executes: REPLACE INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date') 

OK, I understand that. I dont think replace is appropriate.

The only one I need to use is "update" but I cant get it to work.

I want to get the contents of $product placed into the temp_1 field of an existing record. I dont want the other fields of that record interfered with.

If there is existing content within temp_1 then I want it to be overwritten. Currently, because Im dealing with a new field temp_1 is empty.

And currently, Im entering into tbl_members, and later when Ive learnt how, I will do the same in tbl_corporate that Ive recently created.

I have this in the Controller;

PHP Code:
$lcuser $this->session->userdata('user_name');
$product $this->input->post('pro');
$this->username_model->update_product($product); 

And this in the Model;

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


Everything else works except the entry into temp_1.
Reply
#13

Try using set on the array.

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

What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#14

(11-21-2020, 12:23 PM)InsiteFX Wrote: Try using set on the array.

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


No, that didnt work.
Reply
#15

(11-21-2020, 12:23 PM)InsiteFX Wrote: Try using set on the array.

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


Would it help if the number of the column was included?
Reply
#16

(This post was last modified: 11-21-2020, 02:39 PM by InsiteFX.)

Show me you table structure with all column names etc.;

Also check to make sure you are getting the users name.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#17

(11-21-2020, 02:38 PM)InsiteFX Wrote: Show me you table structure with all column names etc.;

Also check to make sure you are getting the users name.

Here is the table structure.

PHP Code:
$data = array('user_id' => $result->user_id'date_reg' => $result->date_reg'user_name' => $result->user_name'pass_word' => $result->pass_word'first_name' => $result->first_name'last_name' => $result->last_name'country_territory' => $result->country_territory'temp_1' => $result->temp_1); 

The users name is derived from;

PHP Code:
$lcuser $this->session->userdata('user_name'); 

And it works coz it appears in the view page that is the photos upload & triggers to send the $product to the database.

I want to do the same in the data upload like this;

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

By the way I retrieve the country_territory for the corporate table the same way.

PHP Code:
$countryterritory $this->session->userdata('country_territory'); 

Ive learned how to get all the pages to redirect which is no longer the problem as it was before.
Reply
#18

(11-21-2020, 02:38 PM)InsiteFX Wrote: Show me you table structure with all column names etc.;

Also check to make sure you are getting the users name.

Ive found the problem. $user needs to be defined in the Model as follows;

PHP Code:
public function update_product($product)
    {
    
$user $this->session->userdata('user_name');
    
$this->db->where('user_name'$user);
    
$data = array('temp_1'=> $product);
    
$this->db->update('tbl_members'$data);
    } 
Reply
#19

(11-21-2020, 02:38 PM)InsiteFX Wrote: Show me you table structure with all column names etc.;

Also check to make sure you are getting the users name.

Hey InsiteFX I have another problem.

In the view page I have the following which works good.

PHP Code:
<?php echo $this->session->userdata('user_name'); ?>

But if I have the following it wont work even though the field has data.

PHP Code:
<?php echo $this->session->userdata('temp_1'); ?>

If I do the same for last_name it works.

PHP Code:
<?php echo $this->session->userdata('last_name'); ?>

But if I change the column name in the table to last_temp & have the following it wont work. If I change both back to last_name it works.

PHP Code:
<?php echo $this->session->userdata('last_temp'); ?>

Ive tried the following but makes no difference.

PHP Code:
<?php echo $this->session->set_userdata('temp_1'); ?>

It appears that anything new wont work, whereas all existing data does work. Ive added temp_1 to the Login Controller & done a fresh Login. And Ive tried different names & tried deleting & reinserting new columns into the table.

Have you any suggestions?
Reply
#20

Ive rebooted & it appears to have fixed my problem.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB