Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialfngr
11,179 PointsAfter filter_input the $id is NULL
Hi everbody!
When trying to get the single_item_array function to work, I stumpled over a problem: the $_GET["id"] value is set as a string with value (i.e.) "2". But when I filter the input I get back a NULL so my query doesnt work und throws an error. my filter_input looks like this:
$id = filter_input(INPUT_GET, $_GET["id"], FILTER_SANITIZE_NUMBER_INT);
some ideas why? what am I doing wrong?
Best regards Matthias
2 Answers
jlampstack
23,932 Points"I'm a student too, but from my understanding you are using $_GET["id"] when you only need "id"
Alena shows the code as this....
$id = filter_input(INPUT_GET, "id", FILTER_SANITIZE_NUMBER_INT);
fngr
11,179 PointsOk I got it to work with filter_var instead of filter_input. So my code now looks like:
if (isset($_GET["id"])) {
$getId = $_GET["id"];
$id = filter_var($getId, FILTER_SANITIZE_NUMBER_INT);
$item = single_item_array($id);
}
But I don't know why it doesnt work with filter_input...