2016-07-23 45 views
-2

我想将数据插入数据库。这是我正在使用的代码。它会插入除图像以外的所有数据(Pic)。MySQL不从一列插入数据

public function insert($hey){ 

    try { 

     $hey = $this->db->query("INSERT INTO addmember(Pic,Firstname,Lastname,Age,Gender,Phonenumber,Location,Member,Department) VALUES('".$hey['pic']."','".$hey['fname']."','".$hey['lname']."','".$hey['age']."','".$hey['gender']."','".$hey['phone']."','".$hey['loc']."','".$hey['group']."','".$hey['department']."')"); 

    } catch (PDOException $e) { 

     echo $e->getMessage(); 
    } 
} 
+0

您是否尝试过使用print_r($ hey);看看照片是否真的包含什么?你检查过数据库中的列的类型吗? – Ibrahim

+0

是请求它仍然工作 –

+0

你能解释一下列的类型和大小吗? – RamRaider

回答

0

您正在对数组$嘿错了索引。 ($哎[“知情同意”根据您的数组转储不正确)

这应该工作:

public function insert($hey){ 

    try { 

     $hey = $this->db->query("INSERT INTO addmember(Pic,Firstname,Lastname,Age,Gender,Phonenumber,Location,Member,Department) VALUES('".$hey['Pic']/* this is where hte error was occuring */."','".$hey['fname']."','".$hey['lname']."','".$hey['age']."','".$hey['gender']."','".$hey['phone']."','".$hey['loc']."','".$hey['group']."','".$hey['department']."')"); 

    } catch (PDOException $e) { 

     echo $e->getMessage(); 
    } 
} 

在一个侧面说明,你为什么不具约束力的投入?

+0

$数据=阵列( 'PIC'=> $ PIC, \t \t \t 'FNAME'=> $姓名, \t \t \t'lname'\t => $姓氏, \t \t \t '年龄'=> $年龄, \t \t \t '性别'=> $性别, \t \t \t '电话'=> $ PHONENUMBER, \t \t \t '禄' \t => $位置, \t \t \t '基团'=> $基, \t \t \t '部门'=> $百货商店 \t \t \t );正在使用上述代码的$ hey ['pic'] cos –

+0

这是什么? – Hiyper

+0

它是我创建的一个数组,因此我可以在函数的顶部使用$ hey [] –