Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.