Problem is with keyword index, Your table's column name is index so it is giving an error. following is the code with escape character `
SET @counter:=0;
SET @previndex:=0;
SET @prevorderindex:=0;
SELECT `index`, orderindex,
@counter:=(CASE WHEN @previndex=`index` AND @prevorderindex=orderindex THEN @counter +1 ELSE 1 END) srno,
@previndex:=`index`,
@prevorderindex:=orderindex
FROM orders1
ORDER BY `index`,orderindex