Why bool(false) goes in the get request?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
7 views
db.php :

// Get a single article by its id get_lesson_by_id function($id) { global $db; $lessons = $db->query("SELECT * FROM entries WHERE id = $id"); foreach ($lessons as $lesson) { return $lesson; } var_dump($lessons); };


lesson.php :

<? require "/home/hskwiki/public_html/db.php" ?><!DOCTYPE HTML><? require "/home/hskwiki/public_html/header.php" ?><? require "/home/hskwiki/public_html/bar.php" ?><? require "/home/hskwiki/public_html/content-lesson.php" ?>


content-lesson.php

<?php $lesson = get_lesson_by_id($_GET['id']);?><?php echo $lesson["text"];?>


And when I ask in url browser get request site.com/lesson.php?=1

produces bool(false)

How to fix it?

Error:

Notice: Undefined index: id in /home/hskwiki/public_html/content-lesson.php on line 7
<? $lesson = get_lesson_by_id($_GET["id"]); ?>

Warning: Invalid argument supplied for foreach() in /home/hskwiki/public_html/db.php on line 21

foreach ($lessons as $lesson) {
by | 7 views

2 Answers

0 like 0 dislike
"SELECT * FROM entries WHERE id = $id"
SQL injection is dangerous.

Why...?
The exact cause is not seen from here, but most likely the record with that id not found, or some problem with the request.

How to fix it?
Include finally the display of errors, or to open the log. To read the error written letters much easier than GUESSING.
by
0 like 0 dislike
site.com/lesson.php?id=1
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
4 answers
0 like 0 dislike
4 answers
0 like 0 dislike
4 answers
110,608 questions
257,186 answers
0 comments
35,389 users