Php mysql插入子查询不工作

Php mysql插入子查询不工作,php,mysql,Php,Mysql,请看我的提问 insert into wp_9m8phu_term_relationships as rel (object_id,term_taxonomy_id,term_order) values ( 'select object_id+1 as object_id from wp_9m8phu_term_relationships where object_id!='' order by object_id desc limit 0,1',

请看我的提问

insert into wp_9m8phu_term_relationships as rel
    (object_id,term_taxonomy_id,term_order)
values
    (
     'select object_id+1 as object_id from wp_9m8phu_term_relationships 
      where object_id!='' order by object_id desc limit 0,1',
     '".$fnds_id."',
     0
)

这是一个无效的查询。在这方面,有人帮我吗。

你需要避开单引号。您的查询应如下所示:

insert into wp_9m8phu_term_relationships as rel (object_id,term_taxonomy_id,term_order)
values('select object_id+1 as object_id from wp_9m8phu_term_relationships 
        where object_id!=\'\' order by object_id desc limit 0,1','".$fnds_id."',0
)

如果您按照第二个值的建议从PHP调用SQL语句,那么您也应该确保转义变量$fnds_id中包含的引号。如果使用mysqli访问数据库,您应该使用。

我认为有语法错误 试试这个


你从哪里打电话来的,php?什么不起作用,是否有错误消息?
insert into wp_9m8phu_term_relationships as rel (object_id,term_taxonomy_id,term_order)
values("select object_id+1 as object_id from wp_9m8phu_term_relationships 
        where object_id<>'' order by object_id desc limit 0,1",'".$fnds_id."',0)