When invoking a multi-line SQL query, you need to Clear()
the SQL
before you then Add()
lines to it, otherwise you will be adding on to a previous query:
ADOQuery1.Close;
ADOQuery1.SQL.Clear; // <-- ADD THIS!!!
ADOQuery1.SQL.Add('insert into FPS_Tbl([MatchID],[kills],[standings],[GrenadeKill],[TimePlayed],[Username],[Comments],[Headshots],[Dates])');
ADOQuery1.SQL.Add('values("' + IntToStr(ids) + '","' + IntToStr(Kills) + '","' + standings + '","' + IntToStr(grenKills) + '","' + times + '","' + user + '","' + comment + '","' + IntToStr(HedShots) + '","' + DateToStr(Now) + '");');
ADOQuery1.ExecSQL;
Otherwise, use the Text
property instead:
ADOQuery1.Close;
ADOQuery1.SQL.Text := 'insert into FPS_Tbl([MatchID],[kills],[standings],[GrenadeKill],[TimePlayed],[Username],[Comments],[Headshots],[Dates]) values("' + IntToStr(ids) + '","' + IntToStr(Kills) + '","' + standings + '","' + IntToStr(grenKills) + '","' + times + '","' + user + '","' + comment + '","' + IntToStr(HedShots) + '","' + DateToStr(Now) + '");');
ADOQuery1.ExecSQL;
That said, your code is subject to an SQL Injection attack. You can avoid that by using AnsiQuotedStr()
for all string inputs:
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('insert into FPS_Tbl([MatchID],[kills],[standings],[GrenadeKill],[TimePlayed],[Username],[Comments],[Headshots],[Dates])');
ADOQuery1.SQL.Add('values("' + IntToStr(ids) + '","' + IntToStr(Kills) + '",' + AnsiQuotedStr(standings,'"') + ',"' + IntToStr(grenKills) + '",' + AnsiQuotedStr(times,'"') + ',' + AnsiQuotedStr(user,'"') + ',' + AnsiQuotedStr(comment,'"') + ',"' + IntToStr(HedShots) + '","' + DateToStr(Now) + '");');
ADOQuery1.ExecSQL;
Or better, by using a parameterized query instead:
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('insert into FPS_Tbl([MatchID],[kills],[standings],[GrenadeKill],[TimePlayed],[Username],[Comments],[Headshots],[Dates])');
ADOQuery1.SQL.Add('values(:PId,:PKills,:PStandings,:PGrenKills,:PTimes,:PUser,:PComment,:PHeadShots,:PDate);');
ADOQuery1.Parameters.ParamByName('PId').Value := IntToStr(ids);
ADOQuery1.Parameters.ParamByName('PKills').Value := IntToStr(Kills);
ADOQuery1.Parameters.ParamByName('PStandings').Value := standings;
ADOQuery1.Parameters.ParamByName('PGrenKills').Value := IntToStr(grenKills);
ADOQuery1.Parameters.ParamByName('PTimes').Value := times;
ADOQuery1.Parameters.ParamByName('PUser').Value := user;
ADOQuery1.Parameters.ParamByName('PComment').Value := comment;
ADOQuery1.Parameters.ParamByName('PHeadShots').Value := IntToStr(HedShots);
ADOQuery1.Parameters.ParamByName('PDate').Value := DateToStr(Now);
ADOQuery1.ExecSQL;