每当我将数据插入MySQL时,为什么会出现此错误?

I have this problem whenever I insert my integer value to my database it looks like this

<h1>A Database Error Occurred</h1>
        <p>Error Number: 1366</p><p>Incorrect integer value: '
11' for column 'code' at row 1</p><p>INSERT INTO `company`(`code`, `Name`) 
                             VALUES('
11', 'John')

my code is in a span and my name is an input type. is there a way to remove the in the values?

ADDITIONAL CODE

function insert_new_name()
        {

        $code = $this->input->get('code');
        $name = $this->input->get('name');

        $sSQL = "SELECT * FROM company WHERE code = ? or Name = ? AND `show` = 1"  ;
        $result = $this->db->query($sSQL, array($code, $name));
            if($result->num_rows() != 0)
                {
                 return json_encode('error');
                }
            else
                {
                $sSQL = "INSERT INTO `company`(`code`, `Name`) 
                         VALUES(?, ?) ";
                $result = $this->db->query($sSQL, array($code, $name));
                $id = $this->db->insert_id();
                $sSQLdisplay = "SELECT * FROM Name where id = '$id' ";
                $resultdisplay = $this->db->query($sSQLdisplay);
                $data = array();
                $row = $resultdisplay->row();
                    $data[] = Array($row->id);
                    $data[] = Array($row->code);
                    $data[] = Array($row->Name);
                    $data[] = Array('');                        
                    $data[] = Array(''); 
                $resultdisplay->free_result();
                return json_encode($data);  
            }
        }   

Use trim() to remove the new line character from that value before binding it to your query:

$code = trim($this->input->get('code'));

Remove char from code field value, code field looks like integer

INSERT INTO `company`(`code`, `Name`) 
                             VALUES('11', 'John')

please user trimfunction,

Like this

$code = trim($this->input->get('code'), " \t
\0\x0B");

OR

$code = trim($this->input->get('code'));

Well it looks like you are trying to insert a string ' 11' into a field that requires an integer. You will need to strip out non-numeric characters from the code value that you want to insert and parse it to an integer, to make the following command:

INSERT INTO `company`(`code`, `Name`) VALUES(11, 'John')

for integer value best option is use intval() to convert any string or null value in integer value

$code = intval($this->input->get('code'));// you will get either 0 or greater then 0

Examples :

  1. $this->input->get('code') this has value 11
    $code = intval($this->input->get('code')); //11

  2. $this->input->get('code') this has value abc11
    $code = intval($this->input->get('code')); //11

  3. $this->input->get('code') this has value abc
    $code = intval($this->input->get('code')); //0