When I am trying to insert a new value in a MySQL database, I have the following error:
Error Number: 1048
Column 'email' cannot be null
INSERT INTO emails(email)VALUES(NULL)
Filename: models/Model_email.php
Line Number: 7
I had not this error when I was running the website on the local server, the error appeared on production. I code in PHP with the framework CodeIgniter.
The code is pretty simple though:
Controler.php
public function addemail(){
ini_set('display_errors','off');
$this->load->model("Model_email","", true);
$this->Model_email->addemail($_POST["email"]);
}
Model_email.php
public function addemail($email){
$sql = "INSERT INTO emails(email)VALUES(?)";
$data = array($email);
$this->db->query($sql,$data);
return $this->db->insert_id();
}
HTML form
<form method="post" action="<?=site_url("/Controler/addemail")?>">
<input type="text" name="email">
<input type="submit">
</form>
When I add a var_dump($email) in the function in Model_email.php or a var_dump($_POST["email"]) in Controler.php, both page shows a NULL. However the method post in the form seems to be right.