3
I am trying to update my database using codeigniter, however the update is not running.
HTML:
<?php echo form_open('Texto/alterarTexto', 'class="form-horizontal"'); ?>
<fieldset>
<legend>Novo texto</legend>
<div class="form-group">
<label class="col-md-1 control-label" for="titulo">Titulo</label>
<div class="col-md-6">
<input id="titulo" name="titulo" type="text" placeholder="" class="form-control input-md" value="<?php echo $dados[0]->titulo; ?>" required disabled>
</div>
</div>
<div class="form-group">
<label class="col-md-1 control-label" for="data">Data</label>
<div class="col-md-2">
<input id="data" name="data" type="hidden" placeholder="" class="form-control input-md" required value="<?php echo $dados[0]->id; ?>">
<input id="data" name="data" type="text" placeholder="" class="form-control input-md" required value="<?php echo $dados[0]->data; ?>">
</div>
</div>
<div class="form-group">
<label class="col-md-1 control-label" for="inputDefault">Texto <br /> <small>Evite grandes textos</small></label>
<div class="col-md-9">
<textarea rows="10" id="area1" cols="120" name="texto"><?php echo $dados[0]->texto; ?></textarea>
</div>
</div>
<div class="form-group">
<label class="col-md-1 control-label" for="salvar"></label>
<div class="col-md-5">
<button id="salvar" class="btn btn-primary btn-lg" type="submit">Salvar</button>
</div>
</div>
</fieldset>
Controller:
public function alterarTexto() {
$data = array( 'id' => $this->input->post('id'),
'data' => $this->input->post('data'),
'texto' => $this->input->post('texto')
);
if ($this->Texto_model->alterarTexto($data)) {
echo "Sucesso!";
} else {
echo "Erro!";
}
}
Model:
function alterarTexto($data) {
$this->db->where('id', $data['id']);
$this->db->set($data);
return $this->db->update('texto', $data);
}
On the controller I put echo
just to find out what part of if
was falling, and what appears is the success message, but nothing changes.
Gives a print_r($data), inside the controller, to see if the data are coming correctly.
– Sr. André Baill
if ($this->Texto_model->alterarText($data)) { print_r($data); die();
– Sr. André Baill