ORDER BY with IF-ELSE statement (DESC doesn't work)
Welcome.

Please notice that you are in a wrong place. 

dba - here you can give your mysql code alone and ask for help. 

You might have asked this question in stackoverflow.

Anyway here is what you miss.

if(isset($_GET["sortfield"])){


is right. But

if(isset($_GET["sorttype"]) == "asc"){  


is not right as the expression to the left of equal condition operator would evaluate to true or false and if you check the logical value == "asc" it will fail. It should be

if(isset($_GET["sorttype"]) and $_GET["sorttype"]== "asc"){  


or simply

if($_GET["sorttype"]== "asc"){  


if you are sure that it is already set (as of the first if).

Also, please go through this before asking. https://stackoverflow.com/help/minimal-reproducible-example

If you had gone through the mentioned page, formatted your question clearly and asked at the right place, you would have got your answer on day one itself for sure.