-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_general_insert_code.php
More file actions
33 lines (31 loc) · 1.34 KB
/
add_general_insert_code.php
File metadata and controls
33 lines (31 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
session_start();
require('connection_DB.php');
if(isset($_POST['submit-book-btn'])){
$bb_id = $_POST['general-id'];
$student_id = $_POST['student-id'];
//$loan_date = $_POST['loan-date'];
$return_date = $_POST['return-date'];
$book_type = $_POST['book-type'];
$check_copy = mysqli_query($con, 'SELECT copy FROM general_book WHERE general_book_id = '.$bb_id.'');
$row = mysqli_fetch_array($check_copy);
$old_copy_number = $row[0];
if($old_copy_number > 0){
$new_copy = ($old_copy_number - 1);
$update_copy = mysqli_query($con, "UPDATE general_book SET `copy` = ".$new_copy." WHERE general_book_id = ".$bb_id."");
if($update_copy){
$query = mysqli_query($con, "INSERT INTO loan(`loan_date`, `return_date`, `loan_status`, `loaner`, `loaner_type`, `book_id`, `book_type`)
VALUES (NOW(), '$return_date', '0', '$student_id', '0', '$bb_id', '$book_type')");
if($query){
header('location: add_lon_return_book.php');
}else{
echo mysqli_error($con);
}
}else{
echo mysqli_error($con);
}
}else{
echo 'This book has not avaliable';
}
}
?>