如何将值更新到单独数据库中的三个表中


how to update values into three tables in separate database?

下面的代码在我的本地主机上,但在远程主机上不起作用,第一个连接工作正常,随后其他数据库连接不起作用。 如何连接多个 MySQL 数据库?

<?php
 $error=''; 
if(isset($_POST['submit']))
{ 
$sno=$_POST['sno'];
$date=$_POST['date'];
$item=$_POST['item'];
$name=$_POST['product'];    
include "connection/order_connection.php";  
$sql2="select item_code from warehouse_stock WHERE item_code='".$item."' and    sno!='".$sno."' ";
$result2=mysql_query($sql2);
if($result2 === FALSE)
{    
die(mysql_error()); // TODO: better error handling
}
if(mysql_fetch_array($result2)>= 1) 
{ 
echo  "Entered Item Code Already in Exists!<br/>";
echo '<script>
$(window).load(function () {
    window.setTimeout(function () {
    window.location.href = "list_products.php";
    }, 3500)
    }); 
    </script>'; 
}
else
{
// product insert into order and warehouse table
$sql1=("update warehouse_stock set date='".$date."',     product_name='".$name."', item_code='".$item."' where sno='".$sno."' ");
 $query1=mysql_query($sql1) or die(mysql_error());
 if($query1)
$sql2=("update order_stock set date='".$date."', product_name='".$name."',  item_code='".$item."' where sno='".$sno."' ");
$query2=mysql_query($sql2) or die(mysql_error());
mysql_close($con);
// product insert into us hub table
include "connection/us_connection.php"; 
$sql3=("update stock_bal set date='".$date."', product_name='".$name."', item_code='".$item."' where sno='".$sno."' ");
$query3=mysql_query($sql3) or die(mysql_error());
mysql_close($con);
// product insert into canada hub table
include "connection/canada_connection.php"; 
$sql4=("update stock_bal set date='".$date."', product_name='".$name."', item_code='".$item."' where sno='".$sno."' ");
$query4=mysql_query($sql4) or die(mysql_error());
mysql_close($con);
header('location:list_products.php');   
echo '<script>
$(window).load(function () {
window.setTimeout(function () {
    window.close();
}, 1500)
}); 
</script>';
//$error="Product details updated successfully!";
}
}
?>

有没有其他方法可以将值更新到表中。?

<?php
$error=''; 
if(isset($_POST['submit']))
{ 
$sno=$_POST['sno'];
$date=$_POST['date'];
$item=$_POST['item'];
$name=$_POST['product'];
// product insert into us hub table1    
$hostname="localhost";
$db_user="root";
$db_pwd="";
$dbname="jasmineus";
$con1 = mysql_connect($hostname,$db_user,$db_pwd);
if (!$con1)
{
  die('Could not connect: ' . mysql_error());
}
mysql_select_db($dbname,$con1); 
$sql3=("update stock_bal set date='".$date."', product_name='".$name."', item_code='".$item."' where sno='".$sno."' ");
$query3=mysql_query($sql3) or die(mysql_error());
mysql_close($con1);
// product insert into canada hub table2
$hostname="localhost";
$db_user="root";
$db_pwd="";
$dbname="jasminecanada";
$con3 = mysql_connect($hostname,$db_user,$db_pwd);
if (!$con3)
{
  die('Could not connect: ' . mysql_error());
}
mysql_select_db($dbname,$con3); 
$sql4=("update stock_bal set date='".$date."', product_name='".$name."', item_code='".$item."' where sno='".$sno."' ");
$query4=mysql_query($sql4) or die(mysql_error());
mysql_close($con3);
$yourURL="list_products.php";
echo ("<script>location.href='$yourURL'</script>");
exit();
//$error="Product details updated successfully!";
}
$yourURL="list_products.php";
echo ("<script>location.href='$yourURL'</script>");
exit();
die(mysql_error());
}
?>