0

Im trying to run this query

("INSERT INTO units SET id="+toID+" AND num="+number+" AND unit_id="+type+"")

this is the log

[2014-05-13 13:09:51] Running query: INSERT INTO units SET id=3 AND num=10 AND unit_id=1

these values are never inserted, it defaults to 0. It only happens on insert queries, i can select fine.

It inserts fine from a php script, however im using Kumulos KScript to run these queries, all have worked fine apart from this one.

Is there a setting on the table that i have missed or something?

Any suggestions?

Many Thanks, Paul.

Daniel W.
  • 31,164
  • 13
  • 93
  • 151
Paulie
  • 51
  • 1
  • 8

3 Answers3

2

INSERT INTO with SET in MYSQL does not need AND as you have

The correct syntax is

INSERT INTO table
SET
       col1 = 'val1',
       col2 = 'val2',
       col3 = 'val3'

OR You can use the following

INSERT INTO table
     ( col1, col2, col3 )
VALUES 
     ( 'val1', 'val2', 'val3' )

http://dev.mysql.com/doc/refman/5.6/en/insert.html

Abhik Chakraborty
  • 44,654
  • 6
  • 52
  • 63
1

How about:

INSERT INTO units ( id, num, unit_id ) VALUES ( toID, number, type )

Or:

INSERT INTO units id=toID, num=number, unit_id=type
Tripp Kinetics
  • 5,178
  • 2
  • 23
  • 37
0

It is not a correct INSERT query.

Try this:

("INSERT INTO units(id, num, unit_id) VALUES ("+toID+", "+number+", "+type+")")
keles
  • 136
  • 4