clay1 Posted August 9, 2009 Share Posted August 9, 2009 When I run $insertSql = "INSERT INTO leads ('$fields[$col]') VALUES ('$vars[$col]')"; $result = pg_query($conn, $insertSql); I get this error: pg_query() [function.pg-query]: Query failed: ERROR: syntax error at or near "'name'" LINE 1: INSERT INTO leads ('name') VALUES ('name of a person') If I print $fields[$col] no quotes are printed just the value Can anyone tell me what my syntax error is? Quote Link to comment https://forums.phpfreaks.com/topic/169447-insert-query-fails/ Share on other sites More sharing options...
Daniel0 Posted August 9, 2009 Share Posted August 9, 2009 Do note the distinction between ' (single quote) which delimits a string literal and the ´ (backtick) which delimits an identifier. You want INSERT INTO table (list of identifiers) VALUES (list of values); Quote Link to comment https://forums.phpfreaks.com/topic/169447-insert-query-fails/#findComment-893983 Share on other sites More sharing options...
clay1 Posted August 9, 2009 Author Share Posted August 9, 2009 OK great. That fixed that error. Now I am getting a similar error which I believe is caused by spaces in my column names, my data or both. Warning: pg_query() [function.pg-query]: Query failed: ERROR: syntax error at or near "River" LINE 1: INSERT INTO leads (name) VALUES (De River) Warning: pg_query() [function.pg-query]: Query failed: ERROR: syntax error at or near "address" LINE 1: INSERT INTO leads (street address) VALUES (6 High Dr) pg_query() [function.pg-query]: Query failed: ERROR: syntax error at or near "id" LINE 1: INSERT INTO leads (party id) VALUES (1076) pg_query() [function.pg-query]: Query failed: ERROR: column "astn" does not exist LINE 1: INSERT INTO leads (market) VALUES (ASTN) Quote Link to comment https://forums.phpfreaks.com/topic/169447-insert-query-fails/#findComment-894026 Share on other sites More sharing options...
tobimichigan Posted August 9, 2009 Share Posted August 9, 2009 Why not use the table variables directly with the sql check or die mysql_error ? Quote Link to comment https://forums.phpfreaks.com/topic/169447-insert-query-fails/#findComment-894029 Share on other sites More sharing options...
Bjom Posted August 9, 2009 Share Posted August 9, 2009 this would not help at all here, would it? Furthermore "or die" is very bad practice. and you line has a syntactical error too. Using "...or trigger_error(mysql_error(), E_USER_ERROR);" is the way - but anyway....that is of no help here. Your errors: You need to use both backticks and quotes in your queries. Enclose all NAMES in backticks and all VALUES (except numerical) in single quotes ' Example: INSERT INTO `leads` (`name`) VALUES ('De River'); Quote Link to comment https://forums.phpfreaks.com/topic/169447-insert-query-fails/#findComment-894056 Share on other sites More sharing options...
clay1 Posted August 11, 2009 Author Share Posted August 11, 2009 I debugged the script I was trying to copy, went through line by line with echo statements until I could get my output to match it.. finally got everything working. Quote Link to comment https://forums.phpfreaks.com/topic/169447-insert-query-fails/#findComment-895308 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.