Php mysqli_query()未返回true?
mysqli\u query没有返回true,连接成功返回true,但当我使用print\r打印$query\u fire时,没有显示任何输出,数据也没有插入数据库 $data是其他php文件中的关联数组Php mysqli_query()未返回true?,php,mysqli,Php,Mysqli,mysqli\u query没有返回true,连接成功返回true,但当我使用print\r打印$query\u fire时,没有显示任何输出,数据也没有插入数据库 $data是其他php文件中的关联数组 public function insert($table,$data) { $this->con = $GLOBALS['con']; $field_set=""; foreach($data as $key=>$v
public function insert($table,$data)
{
$this->con = $GLOBALS['con'];
$field_set="";
foreach($data as $key=>$value)
{
$field_set=$field_set."$key='$value',";//append
}
$query="INSERT INTO $table SET $field_set";
$query_fire=mysqli_query($this->con,$query);
print_r($query_fire);die;
if($query_fire==TRUE)
{
return $query_fire;
}
else
{
return false;
}
}
我已经找到你的错误插入查询,在结束 因此,已删除,使用rtrim结束插入查询 此处更新代码,请检查
public function insert($table,$data)
{
$this->con = $GLOBALS['con'];
$field_set="";
foreach($data as $key=>$value)
{
$field_set=$field_set."$key='$value',";//append
}
$field_set = rtrim($field_set,',');
$query="INSERT INTO $table SET $field_set";
$query_fire=mysqli_query($this->con,$query);
print_r($query_fire);die;
if($query_fire==TRUE)
{
return $query_fire;
}
else
{
return false;
}
}
打印$query并在sql phpmyadmin中运行结果,并将错误放在此处。您的代码易受sql注入攻击。您应该使用准备好的语句。print_r将布尔值转换为整数,因此print_rfalse不会显示任何内容;可能会提供更多信息。“而且可能更有用。”达曼不仅准备了陈述。字段和表名也是注入的来源