Search code examples
phpcodeignitermodel-view-controllerframeworkscodeigniter-3

insert url parameter in mysql with codeigniter


I need your help!

I am new to codeigniter and I am trying to pass a fetch parameter from url, get me the value using the following

My example url is the following: http://localhost/infocargacasosfinal/index.php/creacionacta/?NroGestion=1&NroContacto=103386816

Where what I am rescuing is the value "NroContacto", I have managed to bring me the value with the following line in the controller:

'NroContacto' => $this->input->get('NroContacto');

and show it in the view with the following:

                        <td>
                                          Numero Folio:   <?php echo $nrocontacto; ?> 
                    </td>

that way I have managed to show it in the user's view, but now I can't find a way to save that value in the database when the user clicks the "save" button


Solution

  • You have not shared much information related to your issue. I am assuming that you need two server calls to save the URL parameter into data.

    1. First "http://localhost/infocargacasosfinal/index.php/creacionacta/?NroGestion=1&NroContacto=103386816", is used to render the page with a form to submit.
    2. Second, When the user clicks the submit button in the form, data is stored in a database.

    If this is the case, on first page, you can collect nrocontacto as you have already done in your code and add a hidden input field <input type="hidden" name="nrocontacto" value="<?php echo $nrocontacto; ?>"> inside the form in the view file.

    When the user submit the form, you can grab the value using $nroContacto = $this->input->post('NroContacto', true); (this code goes to form processing controller method). Now you can use CI query builder $this->db->insert('tableName', array('field_name' => $nroContacto)); (Note: add other required fields for insert array) to save it to the Database.