-1

I do want to insert data into my Google Cloud database with using MySQL, I did it fairly well with others table expect this one.

My database structure :

  • item_id int(11) primary key - autoincrement
  • bill_id int(11) foreign key
  • name text
  • unit text
  • quantity int(11)
  • usage long text
  • price float

INSERT INTO BillItem (bill_id , name , unit , quantity , price,usage) VALUES ('8','Mebendazol 500 mg','Viên','5','2500','Chiều trước khi ăn') ;

Again, thank you a bunch for your assistance!

mjwills
  • 23,389
  • 6
  • 40
  • 63
Lắc Lê
  • 27
  • 6
  • 1
    Did you try insert query in my workbench? – Hien Nguyen Jun 07 '19 at 03:27
  • @HienNguyen I did it and received this error, I got an issue on Visual Studio : ": `'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'usage,price) VALUES (9, 'Mebendazol 500 mg','Viên',20,'Trưa sau khi ăn',10000' at line 1'"` – Lắc Lê Jun 07 '19 at 03:37
  • `('8'` Why are you quoting numbers like that? – mjwills Jun 07 '19 at 03:53
  • My query in my workbench `INSERT INTO BillItem(bill_id,name,unit,quantity,usage,price) VALUES (13,'Acetylcystein 200 mg','Kem bôi',20,'Trưa sau khi ăn',14000);` my code in VS : `String query = string.Format("INSERT INTO BillItem(bill_id,name,unit,quantity,usage,price) VALUES " + "({0}, '{1}','{2}',{3},'{4}',{5})", billId, name, un, quan,use,pr);` – Lắc Lê Jun 07 '19 at 04:00
  • Please read https://stackoverflow.com/questions/14376473/what-are-good-ways-to-prevent-sql-injection . – mjwills Jun 07 '19 at 08:01

1 Answers1

1

Issue here is you are using reserved word: usage

Refer to https://dev.mysql.com/doc/refman/8.0/en/keywords.html#keywords-8-0-detailed-U

To fix this avoid using reserved word, otherwise use backticks around the reserved word. `usage`

penleychan
  • 5,370
  • 1
  • 17
  • 28
  • I'm so sorry for asking you further about my problem, `String query = string.Format("INSERT INTO BillItem(bill_id,medName,unit,quantity,howtoUSE,price) VALUES " + "({0}, '{1}','{2}',{3},'{4}',{5})", billId, name, un, quan,use,pr);`. I got a new issue with "Unknown column 'Bill.medicine' in 'field list'', in spite of not having this colummn name in my field list. – Lắc Lê Jun 07 '19 at 04:21
  • 1
    @LắcLê, sorry I'm not sure not enough detail to see the issue. I would recommend you create another question regarding this. With the relevant information. – penleychan Jun 07 '19 at 04:26