The code doesn't make sense because i and j are not defined.
Here's a start in pseudo code:
is this the first click? (selected square == null)
If so, is the clicked square occupied?
If not occupied, print error message and return
save the clicked square in selected square
return
if not the first click then
check if clicked square is occupied,
if occupied print message and return
move piece from selected square to clicked square
clear selected square