【发布时间】:2018-02-07 07:07:43
【问题描述】:
如何选择两个表并通过 id 连接它们以通过事务进行更新? 我尝试使用 prep stmts,但 id 不能作为参数工作.... 交易能做到吗?
// submit
if (isset($_POST['submit']))
{
// Edit ID
if (isset($_GET['edit']))
$ID = $_GET['edit'];
// form input
if (isset($_POST['title'], $_POST['director'], $_POST['year'], $_POST['genre']))
$title = $_POST['title'];
$director = $_POST['director'];
$year = $_POST['year'];
$category = $_POST['genre'];
// required
if ( $title == '' || $director == '' || $year == '' ||$category == '')
{
// generate error message
$error = 'Fält saknas!';
// if either field is blank, display the form again
renderForm($category, $title, $director, $year, $error);
}
else {
// Edit
// auto turn off
mysqli_autocommit($conn,FALSE);
// values
mysqli_query($conn, "INSERT INTO movies (title, director, year)
VALUES ('$title', '$director', '$year') WHERE ID = '$ID'");
mysqli_query($conn, "INSERT INTO category (category)
VALUES ('$category') WHERE ID = '$ID'");
// Commit transaction
mysqli_commit($conn);
echo "<div class='receipt'>Register ".$ID." uppdaterat.<br>
<a href='index.php'>Gå tillbaka</a> </div>";
}
} $conn->close();
【问题讨论】:
-
用 prep stmts 试过,但 id 不能作为参数工作 ...这是为什么呢?准备语句的尝试在哪里?
标签: php sql join parameters