Welcome Guest, Not a member yet? Register   Sign In
Still problems updating, please help
#1

[eluser]Dizza[/eluser]
Hi all,

Im getting really tired of this problem, i have been struggling with this problem for almost 2 weeks now, and still cant find the error. Please can someone help me?

I cant update, i cant even see the updateform with the values of the form, here is my code:

View
Code:
<div id="content">
    &lt;?php     foreach($kandidaten as $kandidaat) { ?&gt;
    &lt;?php echo $kandidaat['functie'];?&gt; &lt;?php echo form_open('admin/aanpassen/'.$kandidaat['id']);?&gt;
    <table>
      &lt;?php
              $functie = array(
                  'functie'=> 'functie',
                  'id'=> 'functie',
                  'class'=> 'watermark',
                  'title'=> 'functie',
                  'value'=> $kandidaat['functie']
              );
              $branche = array(
                  'name'=> 'branche',
                  'id'=> 'branche',
                  'class'=> 'watermark',
                  'title'=> 'branche',
                  'value'=> $kandidaat['branche']
              );            
                  $regio = array(
                  'name'=> 'regio',
                  'id'=> 'regio',
                  'class'=> 'watermark',
                  'title'=> 'regio',
                  'value'=> $kandidaat['regio']
              );        
              $dienstverband = array(
                  'name'=> 'dienstverband',
                  'id'=> 'dienstverband',
                  'class'=> 'watermark',
                  'title'=> 'dienstverband',
                  'value'=> $kandidaat['dienstverband']
              );        
              $dienstverband = array(
                  'name'=> 'kandidaatnr',
                  'id'=> 'kandidaatnr',
                  'class'=> 'watermark',
                  'title'=> 'kandidaatnr',
                  'value'=> $kandidaat['kandidaatnr']
              );    
              $beschrijving = array(
                  'name'=> 'beschrijving',
                  'id'=> 'beschrijving',
                  'class'=> 'watermark',
                  'title'=> 'beschrijving',
                  'value'=> $kandidaat['beschrijving']
              );    

?&gt;
      <tr>
        <td><strong>functie:</strong></td>
        <td>&lt;?php echo form_input($functie) ; ?&gt;</td>
      </tr>
      <tr>
        <td><strong>branche:</strong></td>
        <td>&lt;?php echo form_input($branche); ?&gt;</td>
      </tr>
      <tr>
        <td><strong>regio:</strong></td>
        <td>&lt;?php echo form_input($regio); ?&gt;</td>
      </tr>
      <tr>
        <td><strong>dienstverband:</strong></td>
        <td>&lt;?php echo form_input($dienstverband); ?&gt;</td>
      </tr>
      <tr>
        <td><strong>beschrijving:</strong></td>
        <td>&lt;?php echo form_input($beschrijving); ?&gt;</td>
      </tr>
      <tr>
        <td></td>
        <td>&lt;input type="submit" value="Aanpassen" id="submit" /&gt;&lt;/td>
      </tr>
    </table>
&lt;?php }?&gt;
       &lt;?php echo form_close();?&gt;
  </div>

Controller
Code:
function getkandidaten() {
    $this->load->model('admin_model');
    $data = array();        
                    
        $data['kandidaten'] = $this->admin_model->getkandidaten();
        $this->load->view('aanpassen_kandidaten_view', $data);
}


    function aanpassen()
    {
        $segs = $this->uri->segment(3,0);
        $url =  'admin/aanpassen/'.$segs;
        
            //validation has passed. Now update the database
            $data = array(
                'functie' => $this->input->post('functie'),
                'branche' => $this->input->post('branche'),
                'regio' => $this->input->post('regio'),
                'dienstverband' => $this->input->post('dienstverband'),
                'kandidaatnr' => $this->input->post('kandidaatnr'),
                'beschrijving' => $this->input->post('beschrijving'));
        
            $this->load->model('Admin_model');
            $this->Admin_model->updatekandidaten($data);
            
            $this->load->view('aanpassen_kandidaten_view');    
        }

Model
Code:
function updatekandidaten($data){    
        $segs = $this->uri->segment(3,0);
        $this->db->where('id', $segs);
        $this->db->update('kandidaten', $data);
    }


function getkandidaten() {

        $segs = $this->uri->segment(3,0);
        $query = $this->db->query('SELECT functie, branche, regio, dienstverband, kandidaatnr, beschrijving FROM kandidaten WHERE id = '.$segs.'');
        
        $kandidaten = array();
            
        foreach ($query->result() as $row) {
            $kandidaten[] = array(
                'id' => $row->id,
                'functie' => $row->functie,
                'branche' => $row->branche,
                'regio' => $row->regio,
                'dienstverband' => $row->dienstverband,
                'kandidaatnr' => $row->kandidaatnr,
                'beschrijving' => $row->beschrijving);
        }
        return $kandidaten;
    }

The error that i am getting is as follows:

Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined variable: kandidaten

Filename: views/aanpassen_kandidaten_view.php

Line Number: 82

and

Quote:A PHP Error was encountered

Severity: Warning

Message: Invalid argument supplied for foreach()

Filename: views/aanpassen_kandidaten_view.php

Line Number: 82

Please help me! Sad
#2

[eluser]InsiteFX[/eluser]
My mistake, sorry

This line in your view is wrong!
Code:
<td>&lt;input type="submit" value="Aanpassen" id="submit" /&gt;&lt;/td>

// should be:
<td>&lt;input type="submit" value="aanpassen" id="submit" /&gt;&lt;/td>

InsiteFX
#3

[eluser]jgetner[/eluser]
your variable kandidaten is not defined before you use it in your foreach loop. you must define the variable and it must be an array.
#4

[eluser]Dizza[/eluser]
[quote author="InsiteFX" date="1301522057"]My mistake, sorry

This line in your view is wrong!
Code:
<td>&lt;input type="submit" value="Aanpassen" id="submit" /&gt;&lt;/td>

// should be:
<td>&lt;input type="submit" value="aanpassen" id="submit" /&gt;&lt;/td>
hehe, thanks changed that lol Tongue didnt solve the problem though ^^


[quote author="jgetner" date="1301522408"]your variable kandidaten is not defined before you use it in your foreach loop. you must define the variable and it must be an array.[/quote]

Thanks for the quick reply, but didnt i define the variable in my controller and passed it to my view through the variable $data? Is there a way i can call this variable? I really dont know how to continue Tongue
#5

[eluser]InsiteFX[/eluser]
echo it in your view to see if it is getting passed to it.

InsiteFX
#6

[eluser]jgetner[/eluser]
you must global $kandidaten in your controller as it is only in the scope of your models method getkandidaten() since you defined it in only that method and not as a property of the class.

but this problem could have been fixed with testing each method and varibles for the correct output before you continue
#7

[eluser]Dizza[/eluser]
[quote author="InsiteFX" date="1301524327"]echo it in your view to see if it is getting passed to it.

InsiteFX[/quote]

[quote author="jgetner" date="1301524615"]you must global $kandidaten in your controller as it is only in the scope of your models method getkandidaten() since you defined it in only that method and not as a property of the class.

but this problem could have been fixed with testing each method and varibles for the correct output before you continue[/quote]

Thanks InsiteFX and jgetner!

I already found the error, i was still working in the old controller, not the new one. I used a wrong anchor to my old function which did not pass the variable to my view. Now it works! Only have one strange problem Tongue I can update everything now except functie! But i think i can solve it myself! Thanks for all!




Theme © iAndrew 2016 - Forum software by © MyBB