-1

displayCategories.html.php

<?php
session_start();
?>
<table>
    <tr>
    <th>Category Name</th>
    <th>Description</th>
    <th>Edit</th>
    </tr>
    <?php foreach ($_SESSION['categoryRows'] as $row):
    $categoryName = $row["CategoryName"];
    $description = $row["Description"];
    $categoryId = $row["CategoryId"];
    $url = "templates/displayCategories.html.php";
    ?>
    <?php if (isset($_GET['id']) && ($_GET['id'] == $categoryId)):?>
        <form>abc</form>
    <?php else:?>
        <tr>
        <td><?= $categoryName ?></td>
        <td><?= $description ?></td>
        <td><a href="<?= $url ?>?id=<?= $categoryId ?>">Edit</a></td>
        </tr>
    <?php endif;?>
    <?php endforeach;?>
</table>

When I click Edit the link becomes from

templates/displayCategories.html.php

to

templates/templates/displayCategories.html.php

There are two templates in url! How so?

Sanu0786
  • 571
  • 10
  • 15
Logan Lee
  • 807
  • 9
  • 21

2 Answers2

0

Use absolute URL on links

In your case, use /blah/blah/blah/question 1/templates/displayCategories.html.php

kgbph
  • 841
  • 1
  • 8
  • 26
  • my path is: localhost/blah/blah/blah/question 1/templates – Logan Lee Nov 27 '18 at 05:54
  • @LoganLee I updated my answer. You might have to generate that one. – kgbph Nov 27 '18 at 06:02
  • I think I need to use $_SERVER but $_SERVER['REQUEST_URI'] includes ?id=n so every time I click it appends ?id=n at the end. I just need the URL without ? – Logan Lee Nov 27 '18 at 06:13
  • @LoganLee A quick google got me this code `$url=strtok($_SERVER["REQUEST_URI"],'?');` Reference: https://stackoverflow.com/a/6975045/7381859 That will give you the URL without the query string. – kgbph Nov 27 '18 at 06:17
0

It is because you used relative path reason, please try <a href="/<?= $url ?>?id=<?= $categoryId ?>"

Nick Wang
  • 624
  • 3
  • 6