0

I am trying to insert a records from my database after my update query. the update query works but the insert query doesnt work and it does not show any errors

Here is the code how should i use these queries right?

<?php
    include 'includes/session.php';

    if(isset($_POST['edit'])){
        $id = $_POST['id'];
        $quantity = $_POST['quantity'];
        $name = $_POST['name'];
        $date = date('Y-m-d');

        try{
            $stmt = $conn->prepare("UPDATE stock_list SET quantity=quantity+:quantity WHERE id=:id");
            $stmt->execute(['quantity'=>$quantity, 'id'=>$id]);
            $_SESSION['success'] = 'inventory updated successfully';

            if ($stmt->execute) {
            
            $stmt = $conn->prepare("INSERT INTO stockin_history (name, quantity, status, date_stockin) VALUES (:name, :quantity, :status ,:date_stockin)");
            $stmt->execute(['name'=>$name, 'quantity'=>$quantity, 'status'=>$status, 'date_stockin'=>$date ]);
                
            }
        }
        catch(PDOException $e){
            $_SESSION['error'] = $e->getMessage();
        }
        
        $pdo->close();
    }
    else{
        $_SESSION['error'] = 'Fill up edit inventory form first';
    }

    header('location: inventory.php');

?>
Sencho
  • 13
  • 2

0 Answers0