Bin ein neuer Benutzer auf CodeIgniter
, habe mir andere Beiträge angeschaut und die gegebenen Antworten lösen dieses Problem leider nicht.CodeIgniter - Einzeleintrag nach ID aktualisieren - fehlgeschlagen
Verwenden Sie ein Formular zum Erstellen von Datensätzen (lädt auch Bilddatei und erstellt Link zum Bild als Feld in db) Dies alles funktioniert. Ich versuche jetzt, einen bestimmten Datensatz zu bearbeiten. Ich habe eine Ansicht mit dem Formular, und das funktioniert und ist aus dem db mit $id = $this->uri->segment(3)
vorgefüllt, um den richtigen Datensatz zu greifen - das alles funktioniert.
Wo es fehlschlägt ist dann in der Aktualisierung des Datensatzes.
Mein Controller ...
function edit_stock_vehicle_record()
{
$this->load->library('form_validation');
// field name, error message, validation rules
$this->form_validation->set_rules('title', 'Title', 'trim|required');
$this->form_validation->set_rules('make', 'Make', 'trim|required');
$this->form_validation->set_rules('model', 'Model', 'trim|required');
$this->form_validation->set_rules('fuel', 'Fuel Type', 'trim|required');
$this->form_validation->set_rules('enginesize', 'Engine Size', 'trim|required');
$this->form_validation->set_rules('trans', 'Transmission', 'trim|required');
$this->form_validation->set_rules('reg_no', 'Registration Number', 'trim|required');
$this->form_validation->set_rules('year', 'Year', 'trim|required');
$this->form_validation->set_rules('colour', 'Colour', 'trim|required');
$this->form_validation->set_rules('mileage', 'Mileage', 'trim|required');
$this->form_validation->set_rules('long_desc', 'Description', 'trim|required');
$this->form_validation->set_rules('purchase_price', 'Purchase Price', 'trim|required');
$this->form_validation->set_rules('sale_price', 'Sale Price', 'trim|required');
if($this->form_validation->run() == FALSE)
{
$data['main_content'] = 'vehicle_display2';
$this->load->view('includes/template', $data);
}
else
{
$this->load->model('manage_model');
if($query = $this->manage_model->edit_stock_vehicle_record())
{
$data['main_content'] = 'vehicle_added';
$this->load->view('includes/template', $data);
}
else
{
$data['main_content'] = 'add_vehicle4';
$this->load->view('includes/template', $data);
}
}
}
Mein Modell ....
function edit_stock_vehicle_record()
{
$this->load->helper('array');
$this->load->helper('html');
$id = $this->uri->segment(3);
$config['upload_path'] = 'c:/wamp/www/honest/images';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '5000';
$config['overwrite'] = TRUE;
$config['remove_spaces'] = TRUE;
$this->load->library('upload', $config);
if (! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
$data['main_content'] = 'imageupload';
$this->load->view('includes/template', $data);
echo "FAILED";
}
else
{
$image_data = $this->upload->data();
$vehicle_update_data = array(
'title' => $this->input->post('title'),
'make' => $this->input->post('make'),
'model' => $this->input->post('model'),
'fuel' => $this->input->post('fuel'),
'enginesize' => $this->input->post('enginesize'),
'trans' => $this->input->post('trans'),
'reg_no' => $this->input->post('reg_no'),
'year' => $this->input->post('year'),
'colour' => $this->input->post('colour'),
'mileage' => $this->input->post('mileage'),
'long_desc' => $this->input->post('long_desc'),
'purchase_price' => $this->input->post('purchase_price'),
'sale_price' => $this->input->post('sale_price'),
'image' => $image_data['file_name']
);
$this->load->helper('url');
$id = $this->uri->segment(3);
$update = $this->db->update('stock_vehicles', $vehicle_update_data, array('id' => $id));
return $update;
}
}
ich auch Versionen mit versucht haben ....
$this->db->where('id', $id);
$this->db->update('stock_vehicles', $vehicle_update_data);
Aber dies nicht gelingt auch scheint es, als ob die $id
nicht korrekt erkannt wird.
Wenn ich die oben entfernen und verwenden nur $this->db->update('stock_vehicles', $vehicle_update_data);
es in der Tat jeden Datensatz in der DB nicht aktualisiert (doh!) Glücklicherweise gab es keine ‚echten‘ Daten in da, wenn ich diese entdeckt!
Nicht sicher, warum es die $id
nicht abholt - alle Eingabe dankbar erhalten.
Prost,
DP.
haben u echo ur Variable id jede ID in es kommt, ist –
u kann Ihre URL einfügen –
dieses $ id versuchen = $ this-> uri-> Segment (3, 0) ; –