如何在mysql中更新2个表?

如何在mysql中更新2个表?,mysql,Mysql,我想更新两个名为:routing和routing\u has\u work\u center的表 在工艺路线表中,用户可以编辑说明,而在工艺路线表中,用户可以编辑生产工时 <?php session_start(); // include a php file that contains the common database connection codes include ("dbFunctions.php"); //retrieve computer details from th

我想更新两个名为:routing和routing\u has\u work\u center的表

在工艺路线表中,用户可以编辑说明,而在工艺路线表中,用户可以编辑生产工时

<?php
session_start();
// include a php file that contains the common database connection codes
include ("dbFunctions.php");

//retrieve computer details from the textarea on the previous page
$description = $_POST['description'];
$production_hour=$_POST['$production_hour'];

//retrieve id from the hidden form field of the previous page
$theID = $_POST['routing_id'];

$msg = "";

//build a query to update the table
//update the record with the details from the form
$queryUpdate = "UPDATE routing SET description='$description' WHERE     routing_id = $theID";


//execute the query
$resultUpdate = mysqli_query($link, $queryUpdate) or die(mysqli_error($link));

//if statement to check whether the update is successful
//store the success or error message into variable $msg
if ($resultUpdate) {
$msg = "Record updated successfully!";
} else {
$msg = "Record not updated!";
}
?>

如果要更新2个表,则需要两条update语句。
你有一个。您缺少
路由\u has\u work\u center
中的一个

试着这样做:

$update_routing_center = 'UPDATE routing_has_work_center SET production_hour = $production_hour WHERE routing_id = $theID"`
在通过mysqli\u prepare($link,$update\u routing\u center)发送此语句之后 然后可以将该语句运行到数据库中


编辑:修改它以符合Ed Heal的评论

检查此项

$queryUpdate = "UPDATE routing_has_work_center SET production_hour='$production_hour' WHERE routing_id = '$theID' ";

你听说过SQL注入吗?你应该听说过。在发布的代码中只有一行是
production\u hour
——即
$production\u hour=$\u POST['$production\u hour']-那么您会期望什么呢?请不要像另一个查询一样运行此查询-请参阅以避免SQL注入,因为此anwer建议一个容易发生SQL注入的根本性解决方案:-1感谢警告。我还是编程新手,所以我还在学习一些安全概念@Nielskeurentjes仅通过
mysqli\u prepare
运行语句并不会突然变得安全,因为您仍然在“master”字符串中使用串联。。。