每当我将整数值插入数据库时,我都会遇到此问题
<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('\n11', 'John')
我的代码在一个范围内,我的名字是一个输入类型。有没有办法删除值中的\ n?
附加代码
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);
}
}
最佳答案
使用trim()
从该值中删除新行字符,然后将其绑定到查询:
$code = trim($this->input->get('code'));