0

I have an HTML table with the contents filled in with PHP from my DB

<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      table {
        font-family: arial, sans-serif;
        border-collapse: collapse;
        width: 100%;
      }
      td, th {
        border: 1px solid #dddddd;
        text-align: left;
        padding: 8px;
      }
    </style>
  </head>
    <body>
      <h1>Address Book (PHP Output - view)</h1>
      <table>
    <tr>
      <th>Name</th>
      <th>Email</th>
      <th>Position</th>
      <th>Options</th>
    </tr>
    <?php
        //include 'C:\xampp\htdocs\site\table.php';
        //Establish connection
      $servername = "localhost";
      $username = "root";
      $password = "";
      $dbname = "staff";
      $conn = mysqli_connect($servername, $username, $password, $dbname);
      $statement = "SELECT * FROM staffmembers";
      // Perform query
      $result = mysqli_query($conn, $statement);
      while ($row = mysqli_fetch_assoc($result)) {
            echo '<tr>';
            echo '<td>'. $row['Name'] .'</td>';
            echo '<td>'. $row['Email'] .'</td>';
            echo '<td>'. $row['Position'] .'</td>';
            echo '<td>' . '<a href="edit.php?id=.$row["Name"]".>Edit</a>', '<br>', '<a href="delete.php?row_id=.$row["Name"]".>Delete</a>' . '</td>';
            echo '</tr>'; 
      }
      ?>
  </table>
      
      <p><a href="index.html">Back to home</a></p>
  </body>
</html>

At the bottom of the PHP while loop I use echo to add in edit and delete links, in the tags I have tried to get the name of the staff member, in the row the link was clicked, to display in the next page. This is my code on the next page to get and display the name from the row the link was clicked.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Address Book</title>
  </head>
  <body>
    <h1>Edit Staff</h1>
    <p>Edit Staff Member - Staff Database</p>
    <?php;
        $staffID = $_GET["id"];
        echo($staffID)
    ?>
    </p>
  </body>
</html>

But it isnt working. I can see when testing it that it is almost working because this displays in the URL "http://localhost/site/edit.php?row_id=.$row["

Where am I going wrong?

I have tried changing formatting of the '' and "" on the a tag but I'm not getting anywhere with that

abi110
  • 1

0 Answers0