Невозможно передать идентификатор в URL

У меня есть следующая кнопка, которая должна удалить пункт, который был выбран

$content .= "<td> " . "<a href=/index.php?p=3&id=$id>delete</a>";

Однако это всегда отправляет меня к:

http://localhost/index.php?p=3&id=

Когда p=3, он должен вызвать следующую функцию:

case 3:
$items = new dbconnection();
$content = $items->deleteItem($_GET['id']);

/

public $id;
public function deleteItems($id) {
    $conn = dbconnection::startconnection();

    $this->id = $id;

    $sql = "DELETE FROM items where id = '$this->id'";
    $stmt = $conn->prepare($sql);
    $stmt->execute();

    $content ="<p>" . "<a href=index.php>Go back</a>" . "</p>";

    return $content;
}
public function __construct($id = 1) {

}

Почему идентификатор не отправляется на URL?

0 ответов

Привет, вы пропускаете повторение вашего идентификатора

$content .= "<td> " . "<a href=/index.php?p=3&id=<?=$id?>>delete</a>";

а также

public $id;
public function deleteItems($id) {
    $conn = dbconnection::startconnection();

    $this->id = $id;

    $sql = "DELETE FROM items where id =:id";
    $stmt = $conn->prepare($sql);
    $stmt->execute([':id'=>$this->id]);

    $content ="<p>" . "<a href=index.php>Go back</a>" . "</p>";

    return $content;
}
Другие вопросы по тегам