SQL不会从php获取所有传递的变量

SQL不会从php获取所有传递的变量,php,mysql,sql,Php,Mysql,Sql,我在php函数中有这些sql语句,并且我已经传递了所有需要的变量。我在查询中有2条insert语句。他们将数据插入到同一个表中,第一个插入用于主服务,第二个插入用于我的网站中的附加服务 SQL以某种方式接受$userid和$item_标签的值,并且第一次插入工作正常。除非我将$userid和$item_标签更改为静态值,如'123','122',否则第二次插入将无法工作。(因此,基本上,如果我将它们保留为:userid,:item_label,SQL不会将值插入表中) 但其他重叠变量,如$fil

我在php函数中有这些sql语句,并且我已经传递了所有需要的变量。我在查询中有2条insert语句。他们将数据插入到同一个表中,第一个插入用于主服务,第二个插入用于我的网站中的附加服务

SQL以某种方式接受$userid和$item_标签的值,并且第一次插入工作正常。除非我将$userid和$item_标签更改为静态值,如'123','122',否则第二次插入将无法工作。(因此,基本上,如果我将它们保留为
:userid
:item_label
,SQL不会将值插入表中)

但其他重叠变量,如
$filename
,使用的insert语句都不会导致任何问题

而且,
$userid
不是目标表的索引或任何内容。所以,请帮忙。这是代码

function add_writing_editing_to_table($userid, $item_label, $basic_writing_service_id, $basic_writing_price, $editing_service_subcategory, $editing_service_id, $editing_serivce_price, $filename, $new_filename){

      global $db;
      $query = "INSERT INTO op_cart
                (service_category, userid, item_label, service_subcategory, service_id, is_addon, unit, total_price, filename, new_filename, checkout)
        VALUES
    ('writing', :userid, :item_label, 'basic_writing', :basic_writing_service_id, '0', '1', :basic_writing_price, :filename, :new_filename, '0'),
    ('editing', :userid, :item_label,  :editing_service_subcategory, :editing_service_id, '1', '1', :editing_serivce_price, :filename, :new_filename, '0');";
      $statement = $db->prepare($query);
      $statement->bindValue(':userid', $userid);
      $statement->bindValue(':item_label', $item_label);
      $statement->bindValue(':basic_writing_service_id', $basic_writing_service_id);
      $statement->bindValue(':basic_writing_price', $basic_writing_price);
      $statement->bindValue(':filename', $filename);
      $statement->bindValue(':new_filename', $new_filename);          
      $statement->bindValue(':editing_service_subcategory', $editing_service_subcategory);
      $statement->bindValue(':editing_service_id', $editing_service_id);
      $statement->bindValue(':editing_serivce_price', $editing_serivce_price);
      $statement->execute();
      $statement->closeCursor();

}

您必须为希望输入的每个值包含一个唯一的参数标记 调用PDOStatement::execute()时传入语句。你 在中不能多次使用同名的命名参数标记 准备好的语句,除非启用了仿真模式


您需要重命名seconds
userid
item\u label

如果userid和item\u label没有作为变量传递到第二行值中,则可以实现多行插入,我只是想知道为什么sql会这样做,以及如何修复它。我设法解决了如何更改错误异常和将值作为字符串传递的问题(嗯,很多字符串函数),欺骗sql,使其认为这两个变量是静态值……啊……它起了作用……但是……它真的很傻=。=谢谢。我真的做到了。但它没有起作用。但是$filename和$new_fileneame并没有出现问题,即使我使用了两次……这很奇怪吗?@Bubble,我稍后会测试它。如果我将这两个insert放在两个不同的函数中,并将它们一起调用。SQL只插入我调用的第一个,不插入第二个。@Bubble,看起来像是第二个查询错误。尝试设置PDO以在出错时引发异常。非常感谢。我一定会试试的。