我有一个来自 HTML 表单的变量,该变量当前已发布到我的数据库表中的一个表中。
我想在同一函数中同时将这些相同的变量发布到其他表。这可能吗?这是我当前的 PHP 函数,它已成功发布到一张表
<?php
$var1 = $_POST['var1'];
$var2 = $_POST['var2'];
$var3 = $_POST['var3'];
// Database connection
$conn = new mysqli('localhost','user','password','database');
if($conn->connect_error){
echo "$conn->connect_error";
die("Connection Failed : ". $conn->connect_error);
} else {
$stmt = $conn->prepare("insert into table1(var1, var2, var3) values(?, ?, ?)");
$stmt->bind_param("sss", $var1, $var2, $var3);
$execval = $stmt->execute();
echo $execval;
$stmt->close();
$conn->close();
}
?>
我希望将以下变量发布到同一数据库中的多个表,因此正在考虑以下内容,但它不起作用 -
<?php
$var1 = $_POST['var1'];
$var2 = $_POST['var2'];
$var3 = $_POST['var3'];
// Database connection
$conn = new mysqli('localhost','user','password','database');
if($conn->connect_error){
echo "$conn->connect_error";
die("Connection Failed : ". $conn->connect_error);
} else {
$stmt = $conn->prepare("insert into table1(var1, var2, var3) values(?, ?, ?)");
$stmt->bind_param("sss", $var1, $var2, $var3);
$stmt = $conn->prepare("insert into table2(var1) values(?)");
$stmt->bind_param("s", $var1);
$stmt = $conn->prepare("insert into table3(var2, var3) values(?, ?)");
$stmt->bind_param("ss", $var2, $var3);
$execval = $stmt->execute();
echo $execval;
$stmt->close();
$conn->close();
}
?>
慕慕森
慕森王