0

I have a table that outputs data from a mySQL database, and displays a ID and a button in each column as shown here:

echo "<td>".$claimRow["id"]."</td>";
echo "<td><button type='button' data-toggle='modal' data-target='#exampleModal'>Submit Claim</button></td>";

When you click the button, a modal appears:

<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">

            <?php include('includes/claim.php'); ?>

      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>

This should show a unique modal for each row, but I am unsure how to pass the row ID to the modal, and then to add to my lack of knowledge... I am trying to pass the ID to the include, I tried:

<?php include('includes/claim.php?id='.$claimRow["id"]); ?>

However, for some reason it does not like me passing through the variable on an include file.

Then, how do I overcome this error? I have tried searching but have failed to come across anything similar (Although, I may be using the wrong key words).

BCLtd
  • 1,459
  • 2
  • 18
  • 45
  • That "some reason" is called the difference between access via HTTP, and access via the file system. You are doing the latter here - and the file system does not now the concept of a "query string". – CBroe Jul 21 '22 at 13:10
  • _"Then, how do I overcome this error?"_ - if your included file expects to be able to access `$_GET['id']` - then you can _set_ that in your parent script. (Of course you will have to unset/reset it again after the include, if the sudden existence of this GET parameter could cause problems for the rest of the code that comes after.) – CBroe Jul 21 '22 at 13:11
  • But your included file should also have access to `$claimRow["id"]` directly. (In its top scope; if there is any functions in there that previously simply accessed the value via the superglobal $_GET, then you would either have to import it into those using the `global` keyword, or pass it as a parameter in the function calls.) – CBroe Jul 21 '22 at 13:12
  • That explains it - thanks for the explanation. I guess another solution could be using ajax because that would be using HTTP, am I correct? – BCLtd Jul 21 '22 at 13:13
  • 1
    Do you _need_ `includes/claim.php?id=...` to work in any other context, direct access via URL from the frontend? If not, then simply make it use the variables from the parent scope directly. – CBroe Jul 21 '22 at 13:15
  • Not really, so I could just use this solution - I was just curious :) – BCLtd Jul 21 '22 at 13:15

0 Answers0