Welcome Guest, Not a member yet? Register   Sign In
foreach help needed!!
#1

[eluser]sumit270[/eluser]
Code:
$data = array(
            'id'    =>    $this->input->post('id'),
                'title'     =>  $this->input->post('title'),
                'category'  =>  $this->input->post('category'),
                'body'      =>  $this->input->post('body'),
                'type'      =>  $this->input->post('type'),
                'location'  =>  $this->input->post('location'),
                'company'   =>  $this->input->post('company'),
                'url'       =>  $this->input->post('url'),
                'email'     =>  $this->input->post('email'),
                'ipaddress' =>  $this->input->ip_address(),
                'posted'    =>  time(),
                'c_name'    =>    $this->input->post('c_name'),
                'c_phone'    =>    $this->input->post('c_phone'),
                'status'    =>    $this->input->post('status')
            );
how can i display the above with foreach array
Code:
if ($this->form_validation->run('jobs') == FALSE) {
            $this->load->view('entavo/jobs_edit');
        }else {
        $data = array(
                'id'        =>    $this->input->post('id'),
                'title'     =>  $this->input->post('title'),
                'category'  =>  $this->input->post('category'),
                'body'      =>  $this->input->post('body'),
                'type'      =>  $this->input->post('type'),
                'location'  =>  $this->input->post('location'),
                'company'   =>  $this->input->post('company'),
                'url'       =>  $this->input->post('url'),
                'email'     =>  $this->input->post('email'),
                'ipaddress' =>  $this->input->ip_address(),
                'posted'    =>  time(),
                'c_name'    =>    $this->input->post('c_name'),
                'c_phone'    =>    $this->input->post('c_phone'),
                'status'    =>    $this->input->post('status')
            );
/*
        foreach ($data as $key => $input) {
            echo $key . " " . $input . "<br>";
        }
        print_r($data);
        die();*/
        $this->db->where('id', $this->input->post('id'));
        $this->db->update('jobs', $data);
        $redirect = 'entavo/jobs/details/'. $this->input->post('id');
        redirect($redirect);
My full code looks like that, i want to eliminate the part in which i have to declare everything.
#2

[eluser]Buso[/eluser]
Code:
$data = $_POST;
$data['posted'] = time();
$data['ipaddress'] = $this->input->ip_address();

i don't understand why you have to declare everything

Also, there is a redirect at the end.. Why are you displaying anything if you are going to redirect? It's going to throw an error
#3

[eluser]sumit270[/eluser]
thank you it worked perfectly. so any drawbacks to this method?
#4

[eluser]sumit270[/eluser]
i was following some tutorials, now i am just optimizing my code, so it is reuseable..
i am also looking for a way to put all my option arrays somewhere else.
#5

[eluser]Burak Guzel[/eluser]
[quote author="sumit270" date="1277362649"]thank you it worked perfectly. so any drawbacks to this method?[/quote]

Yes, it's not a safe approach in general.

Let's say you have an "Edit Profile" page. And let's say the users table has a field named "access_level", which is not meant to be updated by the user himself. But the user messes with the form and sends this: $_POST['access_level'] = 'super admin'. Your script will automatically update that field because you copy $_POST to your $data array, which goes into the query.
#6

[eluser]sumit270[/eluser]
excellent point. thank you.
i am just using this method for the general submission, so this short method should be fine. but if i have to write for admin or login system, i will keep that is mind. thank you so much.




Theme © iAndrew 2016 - Forum software by © MyBB