1

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;
3
  • sending to db, means using POST, right Commented Jan 9, 2020 at 23:23
  • Yes, I tried using _POST['codprod'] that is my input, that receive my value =$detalhesEstoque[0]->codprod; but, not work. Commented Jan 9, 2020 at 23:27
  • that's the way to do it, but you need to get the names right: the name field of the form element (e.g. input) needs to match your database table column field, to keep it as simple as possible Commented Jan 9, 2020 at 23:33

1 Answer 1

2

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);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.