How to insert data into a MySQL table in MyQuery (Delphi)

5.5k views Asked by At

I am doing mysql connection by establishing a user-registration application. I use Delphi 7. Myquery (MySQL Access Set) have a problem with adding user information.

MyQuery1.SQL.Clear;
MyQuery1.SQLInsert.Add('INSERT INTO uyeler (nick) VALUES ('+QuotedStr(DBEdit1.text)+')');
MyQuery1.SQLInsert.Add('INSERT INTO uyeler (mail) VALUES ('+QuotedStr(DBEdit2.text)+')');
MyQuery1.SQLInsert.Add('INSERT INTO uyeler (site) VALUES ('+QuotedStr(DBEdit3.text)+')');
MyQuery1.SQLInsert.Add('INSERT INTO uyeler (pass) VALUES ('+QuotedStr(DBEdit4.text)+')');
MyQuery1.CachedUpdates:=True;
MyQuery1.Open;

Error message: MyQuery1: No SQL statement provided.

Note: uyeler: members table.

1

There are 1 answers

0
RRUZ On BEST ANSWER

This message is raised because you are not filling the SQL property, instead you are using the SQLInsert which is a template for query statements.

Some additional tips

  1. You must use the Execute method, The Open method is for SELECT sentences.
  2. use a single insert sentence like

    INSERT INTO uyeler (nick,mail,site,pass) VALUES ('','','','')

  3. Try using parameters, instead of passing the string values directly, in this way you will avoid sql injection attacks and you will increase the performance.