-1

I'm using a Bootstrap modal popup window,this is the button and url

<a id="changeStatusDataID" class="btn btn-success changeStatusDataID" title="Change status" data-bs-toggle="modal" data-id="' . $a['rmaID'] . '" data-bs-target="#complete_rma_modal"><i class="fa-solid fa-check"></i></a>

<div class="modal fade" id="complete_rma_modal" tabindex="-1" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header" style="align-items: center;">
                        <img style="width: 20px; height: 20px; margin-right: 5px;" src="assets/confirm.png" alt="Change Icon">
                        <h5 class="modal-title"> Change RMA Status </h5>
                        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                    </div>
                    <script>
                        $('.changeStatusDataID').click(function() {
                            var id = $(this).attr('data-id');
                            console.log(id);
                            $('#complete_rma_modal').find('.modal-body').html(id);
                        });
                    </script>
                    <div class="modal-body">

                        <?php
                        include('php/database/config.php');

                        $id = "";

                        $sql = "select rmaStatus from rma where rmaID = $id";

                        $result = $connection->query($sql);

                        if ($result->num_rows > 0) {
                            while ($a = $result->fetch_assoc()) {
                                if ($a['rmaStatus'] == 0) {
                                    echo "Are you sure you want to change the status of this RMA to 'Completed'?";
                                } else {
                                    echo "Are you sure you want to change the status of this RMA back to 'In Progress'?";
                                }
                            }
                        }
                        $connection->close()
                        ?>

                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
                        <a onclick="getDataIDAttributeChangeStatus()" class="btn btn-success">Change Status</a>
                    </div>
                </div>
            </div>
        </div>

I've gotten the jquery to go get the data-id, but now I'm lost at trying to get the variable from the modal HTML like the jquery did into the php function to select the rma status' from the database

how would I do this?

iRuben
  • 1
  • 3
  • You'd need to send it to the server – Honk der Hase Jun 01 '22 at 11:17
  • You'd need to make an AJAX request to the server to run some PHP, and then use JS to process the response back from PHP and add any relevant content into your modal. – ADyson Jun 01 '22 at 11:29
  • **Warning:** You are wide open to [SQL Injections](https://php.net/manual/en/security.database.sql-injection.php) and should use parameterized **prepared statements** instead of manually building your queries. They are provided by [PDO](https://php.net/manual/pdo.prepared-statements.php) or by [MySQLi](https://php.net/manual/mysqli.quickstart.prepared-statements.php). Never trust any kind of input! Even when your queries are executed only by trusted users, [you are still in risk of corrupting your data](http://bobby-tables.com/). [Escaping is not enough!](https://stackoverflow.com/q/32391315) – Dharman Jun 01 '22 at 11:57
  • Thanks to everyone <3 – iRuben Jun 01 '22 at 15:37

0 Answers0