0
<?php


$config = require('config.php');
$db = new Database($config['database']);



$heading = 'Note';
$currentUserId = 1;


$note = $db->query('select * from notes where id = :id',[

        'id' => $_GET['id']

    ])->findOrFail();




authorize($note['user_id'] === $currentUserId);





require "views/note.view.php";

i get this error: Warning: Undefined array key "id" in C:\laragon\www\controllers\note.php on line 15

as an example this is working well

<?php

$config = require('config.php');
$db = new Database($config['database']);

$heading = 'My Notes';

$notes = $db->query('select * from notes where user_id = 1')->get();

require "views/notes.view.php";

    'id' => $_GET['id']  

I tried to debugging this part with every method I can think of. Why is the "id" showing as an undefined array?

chancolak
  • 1
  • 2
  • You'd need to show the calling code for anyone to be able to help you. The error message means that there is no such element in the `$_GET` array. If there's a chance it legitimately may not exist, you code should handle that situation. – droopsnoot Jun 12 '23 at 07:07
  • `$_GET` contains the URL query parameters. If you're submitting a form with `method="POST"`, the inputs will be in `$_POST`, not `$_GET`. Try using `var_dump($_GET, $_POST);` to see what parameters you've received. – Barmar Jun 12 '23 at 07:08
  • Please post code, data, and results as text, not screenshots ([how to format code in posts](https://stackoverflow.com/help/formatting)). [Why should I not upload images of code/data/errors?](https://meta.stackoverflow.com/questions/285551/why-should-i-not-upload-images-of-code-data-errors) http://idownvotedbecau.se/imageofcode – Barmar Jun 12 '23 at 07:09
  • @Barmar $_POST method gives me empty array and $_GET method gives me array(1) { ["/note"]=> string(0) "" } – chancolak Jun 12 '23 at 07:35
  • That indicates that your URL ends with `?/note` instead of `?id=something` – Barmar Jun 12 '23 at 15:20

0 Answers0