Jump to content

insert Query fails


clay1

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/169447-insert-query-fails/
Share on other sites

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)

 

 

Link to comment
https://forums.phpfreaks.com/topic/169447-insert-query-fails/#findComment-894026
Share on other sites

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'); 

 

 

Link to comment
https://forums.phpfreaks.com/topic/169447-insert-query-fails/#findComment-894056
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.