2016-05-07 11 views
-1

Ich versuche, die Daten aus der Datenbank auszuwählen und zu aktualisieren. Aber wenn ich auf Update klicke, wird die Meldung "Undefinierte Variable: Daten" angezeigt. Was ist das Problem in Bezug auf $ Daten? ? Ich kann nicht mit test3.php verlinken, um meine Daten zu aktualisieren.PHP-Fehler begegnen Codeigniter

//views/testing2.php

<?php foreach ($data as $row): ?> 
<tr> 
<td><?php echo $row->name; ?></td> 
<td><?php echo $row->email; ?></td> 
<td><?php echo anchor('testing3/view', 'Update'); ?></td> 
</tr> 
<?php endforeach; ?> 

//views/testing3.php

<html> 
<h1>Update</h1> 
<form method="post" > 
<?php foreach ($data as $row): ?> 
<input type="hidden" name="id" value ="<?php echo $row->id; ?>"> 
<label>ID: </label><br> 

<input type="text" name="name" value ="<?php echo $row->name; ?>"> 
<label>ID: </label><br> 

<input type="text" name="email" value ="<?php echo $row->email; ?>"> 
<label>ID: </label><br> 

<input type="submit" id="submit" name="submit" value ="update"> 
<label>ID: </label><br> 
<?php endforeach; ?> 
</form> 
</html> 

//controllers/testing3.php

<?php 
//page name 
class Testing3 extends CI_Controller { 

public function __construct() 
{ 
    parent::__construct(); 
    $this->load->model('testing3_model'); 
} 

function showid() 
{ 
    $data['data']=$this->testing3_model->getsitemodel(); 
    $data['data']=$this->testing3_model->showid($id); 
    $this->load->vars($data); 
    $this->load->view('testing3', $data); 
    $this->load->helper('html'); 
    $this->load->helper('url'); 
    $this->load->helper('form'); 
} 

function updateid() 
{ 

    $data=array(
    'id'=>$this->input->post('id'), 
    'name'=>$this->input->post('name'), 
    'name'=>$this->input->post('name') 
    ); 
    $this->testing3_model->updateid($id, $data); 
    $this->showid(); 
    redirect('testing'); 
} 



public function view($page = 'testing3') //about us page folder name 
{ 

    if (! file_exists('application/views/testing3/'.$page.'.php')) //link 
    { 
     // Whoops, we don't have a page for that! 
     show_404(); 
    } 

    $data['title'] = 'Testing3'; 
    //$data['title'] = ucfirst($page); // Capitalize the first letter 
    $this->load->helper('html'); 
    $this->load->helper('url'); 
    $this->load->helper('form'); 
    $this->load->view('templates/header', $data); 
    $this->load->view('testing3/'.$page, $data); 
    $this->load->view('templates/footer', $data); 
} 
} 

// models/testing3_model.php

<?php 
class Testing3_model extends CI_Model{ 

public function __construct() 
{ 
    $this->load->database(); // to authorize connection to the database 
} 
//fetch record 
public function getsitemodel() 
{ 
    $data = $this->db->get('testing'); //pass data to query 
    return $data->result(); 
} 
//fetch selected record 
public function showid($data) 
{ 
    $this->db->select('*'); 
    $this->db->from('testing'); 
    $this->db->where('id', $data); 
    $data = $this->db->get(); 
    return $data->result; 
} 
//update record 
public function updateid($id, $data) 
{ 
    $this->db->where('id', $id); 
    $this->db->update('testing', $data); 
} 

} 
?> 
diese
+0

Mögliche Duplikat [PHP: "Hinweis: Nicht definierte Variable" und "Notice: Undefined index"] (http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-und-notice-undefined-index) – Chris

+0

@Chris Ich glaube nicht, dass dies die mögliche Verdopplung von http://stackoverflow.com/questions/4261133/php-notice ist -undefined-variable-and-notice-undefined-index nur weil OP hier wissen möchte, warum $ data nicht vom Controller zur Ansicht übergeben wurde. – JiteshNK

+0

Hinweis: Ihr Dateiname des Controllers sollte Testing3.php not testing3.php sein Gleiches gilt für Ihre Modelle. – user4419336

Antwort

0

Wechsel:

function updateid() 
{ 

    $data=array(
    'id'=>$this->input->post('id'), 
    'name'=>$this->input->post('name'), 
    'name'=>$this->input->post('name') 
    ); 
    $this->testing3_model->updateid($id, $data); 
    $this->showid(); 
    redirect('testing'); 
} 

dazu:

function updateid() 
{ 

    $data=array(
    'id'=>$this->input->post('id'), 
    'name'=>$this->input->post('name'), 
    'name'=>$this->input->post('name') 
    ); 
    $this->db->where('id', $this->input->post('id')); 
    $this->db->update('yourtablename', $data); 

    redirect('testing'); 
}