[eluser]Unknown[/eluser]
Hello people!
1º) Sorry for my english, i'm a Brazilian developer!
2º) I have a problem with a damn variable. I need your help! Look it:
In first page(The view), my code is:
print '<td>Cidade</td><td>';
print form_dropdown('nomedacidade', $cidade);
print '</td></tr>';
And in the Model is:
$postado = $this->input->post('nomedacidade');
$query = $this->db->query( 'SELECT * FROM tb_cidade where nome = "'.$postado.'"');
foreach ($query->result() as $rowcidade)
{
$cidade = utf8_decode($rowcidade->id);
}
$this->db->insert( 'tb_lista', array( 'id' => NULL, 'nome' => $this->input->post ('nome'), 'sobrenome' => $this->input->post('sobrenome'),'ddd' => $this->input->post ('ddd'), 'fone' => $this->input->post( 'telefone' ), 'rua' => $this->input->post( 'endereco' ), 'numero' => $this->input->post( 'numero' ), 'cidade_id' => $cidade));
In this mode, the system return the error:
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: cidade
Filename: models/listatelmodel.php
Line Number: 31
and
Error Number: 1048
Column 'cidade_id' cannot be null
INSERT INTO `tb_lista` (`id`, `nome`, `sobrenome`, `ddd`, `fone`, `rua`, `numero`, `cidade_id`) VALUES (NULL, 'Test', 'Test', '99', '99999999', 'xxxxxx xxxxx', '222', NULL)
Ok... But, if i set the variable $postado with a name of the city of the DB, ex:
$postado = "name_of_db";
The system inserts the data correctly!
How do I fix the error of the variable "$postado"? Thanks in advance!