MYSQL variable in function
This line

set @URLID := (SELECT ifnull(id,0) FROM url_productivity WHERE url = @newShortURL LIMIT 1);


isn't returning any rows at all, therefore @URLID retains the value set in the preceding line i.e. -1.