Welcome Guest, Not a member yet? Register   Sign In
Data from POST in my Model?
#1

[eluser]Unknown[/eluser]
I have:

Code:
function get_by_city(){
        $sql = "SELECT * FROM country WHERE city = ?";
        $q = $this->db->query($sql, 'CityName';  // I will hear insert data from FORM
                                                 // Mayby  $this->input->post('name')
        
        if($q->num_rows() > 0){
            foreach ($q->result() as $row){
                $data[] = $row;
            }
            return $data;
        }
    }

My view

Code:
<?php echo form_open('controller_name/add'); ?>
        <p>
            <label for="nazwa">Name:</label>
            &lt;input type="text" name="nazwa" id="nazwa"/&gt;

        </p>

        
            &lt;input type="submit" value="Submit"/&gt;
            &lt;?php echo form_close(); ?&gt;

I will hear "'CityName'" insert data from form.
How to do?
#2

[eluser]solid9[/eluser]
Sorry My friend you are not following the MVC pattern.

fetch the post in controller and then validate it then throw it in model.

What is the use of using CodeIgniter if you are not following MVC?

#3

[eluser]CroNiX[/eluser]
See the User Guide for Query Bindings. Your 2nd parameter to the query needs to be an array of the bindings in order.
#4

[eluser]Unknown[/eluser]
Code:
function city(){
        $data = array(
            'city' => $this->input->post('city')
        );
        
        $this->country_model->by_city($data);
        redirect('/country/index/', 'refresh');
    }


Model country_model

Code:
function by_city(){
        $sql = "SELECT * FROM country WHERE city = ?";
        $q = $this->db->query($sql, $data);
        
        if($q->num_rows() > 0){
            foreach ($q->result() as $row){
                $data[] = $row;
            }
            return $data;
        }
    }

Now is OK ?




Theme © iAndrew 2016 - Forum software by © MyBB