Insert into MySQL Table PHP

后端 未结 5 887
悲&欢浪女
悲&欢浪女 2021-01-13 22:37

I am having some trouble making a simple form to insert data into a MySQL table. I keep getting this SQL error:

\"Error: You have an error in your SQL

5条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-13 23:20

    You have an extra quote and you need ticks around your table name as it contains a space.

    INSERT INTO current stock ('ItemNumber', 'Stock')
    VALUES
    ('$_POST[ItemNumber]','$_POST[Stock]'')";
    

    should be:

    INSERT INTO `current stock` (`ItemNumber`, `Stock`)
    VALUES
    ('$_POST[ItemNumber]','$_POST[Stock]')";
    

    FYI, you also wide open to SQL injections

提交回复
热议问题