如何通过复选框减去数据库中每本书的值

时间:2017-08-10 14:49:15

标签: php mysqli

我想减去书籍副本的值,其中id和书籍ID将匹配,并且该书籍的book_copies将减1,因为用户选择并借用它,谢谢你帮助我

This is the table

borrow_save.php

$id=$_POST['selector'];
$member_id  = $_POST['member_id'];
$due_date  = $_POST['due_date'];

if ($id == '' ){ 
    header("location: borrow.php");
}else{
    mysqli_query($dbcon,"insert into borrow 
                    (member_id,date_borrow,due_date) 
                values ('$member_id',NOW(),'$due_date')")
        or die(mysqli_error($dbcon));
    $query = mysqli_query($dbcon,"select * 
                              from borrow 
                              order by borrow_id DESC")
        or die(mysqli_error());

    $row = mysqli_fetch_array($query);
    $borrow_id  = $row['borrow_id']

    $N = count($id);
    for($i=0; $i < $N; $i++) {
        mysqli_query($dbcon,"insert borrowdetails 
                                (book_id,borrow_id,borrow_status) 
                        values('$id[$i]','$borrow_id','pending')")
                or die(mysqli_error($dbcon));

        mysqli_query($dbcon,"UPDATE book 
                                SET book_copies = book_copies - 1 
                             where book_id='$book_id'"); 
    <!-- this is the book that i code to minus the book copies 
andthis is also the error -->

    }
?>  
<script>alert('Successfully Borrow!');
window.location='borrow.php';</script> 
<?php
}  
?>

borrow.php

$cn=count($id);
for($i=0; $i < $cn; $i++)

    if($copy > 0){ 
?>
<tr class="del<?php echo $id ?>">
    <td><?php echo $row['book_id']; ?></td>
    <td><?php echo $row['book_title']; ?></td>
    <td><?php echo $row ['catalog']; ?> </td> 
    <td><?php echo $row['author']; ?> </td> 
    <td><?php echo $row['publisher_name']; ?></td>
    <td width=""><?php echo $row['status']; ?></td>

<?php 
    include('toolttip_edit_delete.php'); 
?>
    <td width="20">
        <input id="" class="uniform_on" name="selector[]" type="checkbox" value="<?php echo $id; ?>">

    </td> 
</tr>
<?php   
    } 
?>

0 个答案:

没有答案