0

I have a table reading out a few columns of a db, with an edit button in each row. All I am trying to do is, when the edit button is clicked, that row is displayed with all of its columns in another page. Any help would be great. I know it's simple, but I can get it to work. I am able to navigate to the next page, but not sure how to carry the id of the specific row and read that out. Thanks.

index. php

<form id="mainform" action="editFunding2.php">
  <div class='row'>
    <div class='col-12'>
      <div class='table table-responsive'>
        <table class='table table-striped table-bordered datatable active' id='grantTable'>
          <thead>
              <tr>
                <th>FP ID</th>
                <th>Short Title</th>
                <th>PI</th>
                <th>Department</th>
                <th>Funding Type</th>
                <th>Change Funding Type</th>
              </tr>
          </thead>
          <tbody>
            <?php
            //Foreach loop iterates through each column of $getallrows function
            foreach($allRows as $rowID => $rowInfo){ ?>
              <tr>
                <td><?php echo $rowInfo['fpID'];?></td>
                <td><?php echo $rowInfo['shortTitle'];?></td>
                <td><?php echo $rowInfo['PI'];?></td>
                <td><?php echo $rowInfo['Department'];?></td>
                <td><?php echo $rowInfo['fundingType'];?></td>
                <!--Create dynamic id -->
                <?php $rdDrop = "ddgrantType_".$rowInfo['fpID'];?>
                  <td>
                    <button type="submit" class="btn btn-danger" name="action" value='Change Funding Type'>Change Funding</button>
                  </td>
                </tr>
              <?php } ?>
            </tbody>
          </table>
        </div>
      </div>
    </div>
  </form>
My editFunding2.php page

  <div class='row'>
        <div class='col-12'>
          <div class='table table-responsive'>
            <table class='table table-striped table-bordered datatable active' id='grantTable'>
              <thead>
                  <tr>
                    <th>FP ID</th>
                    <th>Short Title</th>
                    <th>PI</th>
                    <th>Department</th>
                    <th>Division</th>
                    <th>Sponsor Name</th>
                    <th>Project Start</th>
                    <th>Project End</th>
                    <th>Funding Type</th>
                    <th>Yes/No</th>
                    <th>Proper Type If No</th>
                    <!-- <th>Exclusions</th>
                    <th>FP Durtation</th> -->
                    <th>Comment</th>
                  </tr>
                  </thead>
                  <tbody>
                    <?php
                    session_start();
                    $editRow = $_REQUEST['fpID'];
                    $mssql = mysqli_query("SELECT * FROM spacing.METADATA_WEBFORM WHERE FUNDING_PROPOSAL_ID = $fpID' ") or die (mysqli_error());
                    while($rowInfo = mysqli_fetch_array($mssql)) {
                   ?>
                      <tr>
                        <td><?php echo $rowInfo['fpID'];?></td>
                        <td><?php echo $rowInfo['shortTitle'];?></td>
                        <td><?php echo $rowInfo['PI'];?></td>
                        <td><?php echo $rowInfo['Department'];?></td>
                        <td><?php echo $rowInfo['Division'];?></td>
                        <td><?php echo $rowInfo['sponsorName'];?></td>
                        <td><?php echo $rowInfo['Date_Project_Start']->format('Y-m-d');?></td>
                        <td><?php echo $rowInfo['Date_Project_End']->format('Y-m-d');?></td>
                        <td><?php echo $rowInfo['fundingType'];?></td>
                      <?php } ?>
                        <!--Create dynamic id -->
                        <?php $rdDrop = "ddgrantType_".$rowInfo['fpID'];?>
                      <td>
                        <div class="form-check">
                          <label class="form-check-label">
                            <input type="radio" class='form-check-input' name="rdGrant[<?php echo $rowInfo['fpID'];?>]" value="Yes" id="rdYes" onclick="disable('<?php echo $rdDrop;?>')" checked/> Yes
                          </label>
                        </div>
                        <div class="form-check">
                          <label class="form-check-label">
                              <input class='form-check-input' type="radio" name="rdGrant[<?php echo $rowInfo['fpID'];?>]" value="No" id="rdNo" onclick="enable('<?php echo $rdDrop;?>')"/> No
                          </label>
                        </div>
                      </td>
                      <td>
                        <div class="dropdown">
                          <select class='form-control' name="ddgrantGroup[<?php echo $rowInfo['fpID'];?>]" id="<?php echo $rdDrop;?>" disabled>
                            <option value=''>Select Proper Funding Type</option>
                            <option value="Corporate Sponsor">Corporate Sponsor</option>
                            <option value="Federal">Federal</option>
                            <option value="Foundation Selected">Foundation Selected</option>
                            <option value="Internally Funded">Internally Funded</option>
                            <option value="State/Local">State/Local</option>
                          </select>
                        </div>
                      </td>
                      <td>
                        <div class="comment">
                          <textarea class="form-control" aria-label="With textarea" name="grantComment[<?php echo $rowInfo['fpID'];?>]" id="grantComment" placeholder="Comments"></textarea>
                        </div>
                      </td>
                    </tr>
                </tbody>
              </div>
            </div>
          </div>
        <div class='row'>
          <div class='col-12 text-right'>
            <button type="submit" class="btn btn-secondary formsubmitbttn" name="action" value='save'>Save</button>
            <button type="submit" class="btn btn-primary formsubmitbttn" name="action" value='complete'>Complete and Save</button>
          </div>
        </div>
    </div>
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
  • 1
    your code is **vulnerable** to **sql injection** please use **prepared statemenst with parameters** see https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php – nbk Jun 11 '20 at 18:36

1 Answers1

-1

Change your button to a

<a href="editFunding2.php?id=<?= $rowInfo['fpID']; ?>">My Link to xx</a>

In editFunding2.php :

$editRow = $_GET['id'];
ShadeBob
  • 64
  • 4