写一个php修改的代码,数据库包含a.id,bookname,categoryName,salePrice,picture,publishingName from books AS a INNER JOIN books_category AS b ON a.categoryId=b.id
时间: 2024-03-05 11:55:06 浏览: 71
以下是一个简单的 PHP 代码示例,用于更新 `books` 表中的数据:
```php
<?php
// 连接数据库
$conn = mysqli_connect("localhost", "username", "password", "database_name");
// 检查连接是否成功
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
// 获取要更新的数据
$id = $_POST['id'];
$bookname = $_POST['bookname'];
$categoryName = $_POST['categoryName'];
$salePrice = $_POST['salePrice'];
$picture = $_POST['picture'];
$publishingName = $_POST['publishingName'];
// 构造 SQL 语句
$sql = "UPDATE books a
INNER JOIN books_category b ON a.categoryId = b.id
SET a.bookname='$bookname', a.categoryName='$categoryName', a.salePrice='$salePrice',
a.picture='$picture', a.publishingName='$publishingName'
WHERE a.id='$id'";
// 执行 SQL 语句
if (mysqli_query($conn, $sql)) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . mysqli_error($conn);
}
// 关闭数据库连接
mysqli_close($conn);
?>
```
请注意,此示例代码仅供参考,并且需要根据您的实际情况进行适当修改和调整。
阅读全文