我有一个问题,您看到我借了一本书来获取book_id
,并且借阅日期设置为今天的日期,但是每本书都有一个days_id
值,需要将其添加到borrow_date
的一天,现在我很难从我选择的date_id
中获取book_id
并将其添加到borrow_date
中,以便生成{自动{1}}
这是我的PHP代码
due_date
这是我的HTML代码
<?php
include 'connect.php';
$librarian_id = $_POST['librarian_id'];
$member_id = $_POST['member_id'];
$book_id = $_POST['book_id'];
$date_borrow = $_POST['date_borrow'];
$status_id = $_POST['status_id'];
$days = "SELECT days_id, book_id FROM book_setup
WHERE book_id = '$book_id' AND days_id = " . $row['book_id'] . " ";
$result = mysqli_query($conn, $days);
$due_date = date('Y-m-d', strtotime($date_borrow. ' + $result days'));
if ($librarian_id == '') {
echo "librarian is empty";
}
else if ($member_id == '') {
echo "member id is empty";
}
else if ($book_id == '') {
echo "book is empty";
}
else if ($date_borrow == '') {
echo "date borrow is empty";
}
else if ($status_id == '') {
echo "status is empty";
}
else if ($due_date == '') {
echo "due date is empty";
}
else {
$sql = " INSERT INTO borrow_book (librarian_id, member_id,
book_id, date_borrow, due_date, status_id)
VALUES
('$librarian_id', '$member_id', '$book_id',
'$date_borrow', '$due_date', '$status_id' ) ";
if ($conn->query($sql) === TRUE)
{
$message = "Borrowing book successful";
echo "<script type='text/javascript'>alert('$message');</script>";
}
else
{
$message = "Borrowing book failed Failed";
echo "<script type='text/javascript'>alert('$message');</script>";
}
}
$conn->close();
?>
this is my database for borrowing book
and this is where I get the book that is available to borrow
答案 0 :(得分:0)
执行以下操作:
$res = mysqli_query($con, " SELECT days_id FROM book_setup WHERE book_id = '$book_id' ");
$days = mysqli_fetch_assoc($res)['days_id'];