0

I have been stuck on SQL Query error for 2 days and as a result I have decided to use Exception handling in order to locate where the actual error is. But the problem is that the SQL Queries are not working and the Exceptions I have set are not showing anything. This is the part of code that has the problem

        try {
            $sql = "SELECT * FROM cart WHERE userID = ?";
            $stmt = mysqli_stmt_init($conn);
            mysqli_stmt_prepare($stmt, $sql);
            mysqli_stmt_bind_param($stmt, "i", $userID);
            mysqli_stmt_execute($stmt);
        } catch (Exception $e) {
            echo 'Message:' . $e->getMessage();
        }
        $results = mysqli_stmt_get_result($stmt);
        while ($row = mysqli_fetch_assoc($results)) {
            $itemName = $row['name'];
            $quantity = $row['quantity'];
            try {
                $sql = "INSERT INTO order_details (name,quantity,userID) VALUES (?,?,?);";
                $stmt = mysqli_stmt_init($conn);
                mysqli_stmt_prepare($stmt, $sql);
                mysqli_stmt_bind_param($stmt, "sii", $itemName, $quantity, $userID);
                mysqli_stmt_execute($stmt);
            } catch (Exception $e) {
                echo 'Message:' . $e->getMessage();
            }
        }
        header('Location:finishOrder.php');
    } else
        header('Location:login.php');
}
Dharman
  • 26,923
  • 21
  • 73
  • 125

0 Answers0