[英]PHP: Insert data from form and another table in the same table
I want to insert data from a form and another table where inv_id = "'.$inv.'"
are in the same table "history"
($inv
is data input from form) (sorry for my bad english) 我想从表单和另一个表中插入数据,其中
inv_id = "'.$inv.'"
在同一表"history"
($inv
是从表单输入的数据)(对不起,我的英语不好)
Actually my query: 其实我的查询:
$query2 = "INSERT INTO istoric SET id_user = '".$user."',id_equipment = '".$nr_inv."',start = '".$startdate."',end = '".$enddate."',comment = '".$comment."'";
$id = "INSERT INTO `istoric`(`condition`) SELECT `status` FROM `echipament`WHERE `nr_inventar` = '".$nr_inv."'";
How to combine two query? 如何结合两个查询? Now this query insert data in two different rows.
现在,此查询将数据插入到两个不同的行中。
History table: 历史记录表:
You could use a sub-query to generate the value for the condition
field: 您可以使用子查询为
condition
字段生成值:
INSERT INTO
`istoric`
SET
`id_user` = '".$user."',
`id_equipment` = '".$nr_inv."',
`start` = '".$startdate."',
`end` = '".$enddate."',
`comment` = '".$comment."',
`condition` = (
SELECT
`status`
FROM
`echipament`
WHERE
`nr_inventar` = '".$nr_inv."'
);
Also based on how you've formatted your query, you should used prepared statements for your queries instead of injecting the variables directly into your query 同样根据查询的格式,应该为查询使用准备好的语句,而不是将变量直接注入查询中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.