what is the best way to solve this problem

presently am doing an assignment. for the past hour or have been experiencing one error to the next with it. it is website am doing where a user can register, login, view their profile etc.
one part of the assignment is where u have to insert and display images on the site using php.

I get thru in some aspect of the assignment concerning the inserting and displaying images. i cant get the images to display, dont know if there is something wrong with the code or what. I am currently getting this errors. have tried everything that I can think of. search on the net, got a few ideas, tried it out but nothing seem to be working. I have only 2 more day to finish this assignment. I am on crunch time here. so any solution would be greatly appreciated.
these are the two errors
error no. 1: Notice: Undefined variable: sql in C:\wamp64\www\luana_itec244\php\upload.php on line 22
error no. 2: Notice: Undefined variable: sql in C:\wamp64\www\luana_itec244\php\upload.php on line 22

they are both on the same line. here is my codes. I need some answers not people just viewing my questions and passing it str8. much thanks in advance.

I dont speak php, but since nobody else has answered...
is php like oher languages where the scope of a variable is its immediately containing block? Because if so $sql is only in scope thru lines 16-19. If not, please ignore this.

Votes + Comments

ryantroop:If I recall, PHP does not hoist like JavaScript. This is the problem.

As far as I recall, IF statements don't have their own scope in PHP. What is the URL you are visiting? If you are getting this error, chances are $_GET["img_id"]) isn't set.

You're referencing $img_id on line 18, but you never initialized this variable

You're including the text $img_id in your string, instead of the value stored by the $img_id variable

It also doesn't really make sense to set $sql on line 18 if $_POST['submit'] wasn't set, as you won't need the SQL statement if you're not connecting to the DB through the IF statement on 20. So combine the conditions into one as follows.