Everton Thomazi
Everton Thomazi

Reputation: 17

Send variable value from view to mysql

In my cart I have a value that I need send to order_items, I have sent my variable to view and it's displaying correctly, but when save order, the value return NULL. I have checked all data, but probably the problem is how I'm sending.

Controller:

$dataProdutos['detalhesEstoque'] = $this->produtos_model->detalhesEstoque('23');

View: Displaying correctly.

<?= $detalhesEstoque[0]->codprod ?>

How I'm trying to send to MySQL using this variable:

$detalhesEstoque[0]->codprod;

Upvotes: 1

Views: 55

Answers (1)

Agung Widhiatmojo
Agung Widhiatmojo

Reputation: 169

You can send variable data from your view to controller then save to database using POST method

for example at view

    <form action="<?php echo site_url('datasave/save_action'); ?>" method="post">
           <input type="text" class="form-control" name="codprod" id="codprod" value="<?php echo $detalhesEstoque[0]->codprod; ?>" readonly ?>
    </form>

at controller

       public function save_action() 
         {
              $data= array(
               'codprod' => $this->input->post('codprod',TRUE),
                );

       $this->Codprod_model->insert($data);

at model

function insert($data)
{
    $this->db->insert('codprodtable', $data);
}

Upvotes: 2

Related Questions