I am trying to insert some data into a database, and am getting "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 'Pawn_Num='1', Pawn_Port='LW3', Pawn_Path='\\\\PS1\\LPT1', Pawn_Mod='', Rec_Num='' at line 1" My code is as follows: mysql_query("INSERT INTO printers SET cust_no='$cust_no' Pawn_Num='$Pawn_Num', Pawn_Port='$Pawn_Port', Pawn_Path='$Pawn_Path', Pawn_Mod='$Pawn_Mod', Rec_Num='$Rec_Num', Rec_Port='$Rec_Port', Rec_Path='$Rec_Path', Rec_Mod='$Rec_Mod', Rep_Num='$Rep_Num', Rep_Port='$Rep_Port', Rep_Path='$Rep_Path', Rep_Mod='$Rep_Mod', Lab_Num='$Lab_Num', Lab_Port='$Lab_Port', Lab_Path='$Lab_Path', Lab_Mod='$Lab_Mod', Jew_Num='$Jew_Num', Jew_Port='$Jew_Port', Jew_Path='$Jew_Path', Jew_Mod='$Jew_Mod'") or die(mysql_error()); PHP: does anyone have any idea what i'm doing wrong here? Thanks in advance!
Hi, yes coz youre trying to insert a data, not updating or vice versa. Check your SQL statement example insert: INSERT INTO mytable(myfield1) VALUES('myvalue') example update UPDATE mytable SET myfield1='myvalue' Thanks, Mike
You're missing a comma between.... cust_no='$cust_no' and Pawn_Num='$Pawn_Num' cust_no='$cust_no', Pawn_Num='$Pawn_Num'
Mike, you can perform inserts that way. See 2nd example here... http://dev.mysql.com/doc/refman/4.1/en/insert.html INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE] [INTO] tbl_name [(col_name,...)] VALUES ({expr | DEFAULT},...),(...),... [ ON DUPLICATE KEY UPDATE col_name=expr, ... ] Or: INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE] [INTO] tbl_name SET col_name={expr | DEFAULT}, ... [ ON DUPLICATE KEY UPDATE col_name=expr, ... ] Code (markup): The problem is a missing comma in the guy's statement. See my other post on this thread.
But I am adding a new row to the database. I do want to use INSERT, don't I? Or are you just saying that I need to put column1,column2,column3, VALUES data1,data2,data3? I'm a little confused because from what I've read I think you should be able to do it the same way as an update. eg.. column1='data1',column2='data2' and so on. Thanks for your help.
No,l Greenmethod. your syntax is acceptable in MySql - though it's not standard SQL which would use columns VALUES data format. Your problem is simply a missing comma.