[SOLVED] SQL Syntax Error: 1604

10 years 6 months ago - 10 years 6 months ago #234607 by don5420
[SOLVED] SQL Syntax Error: 1604 was created by don5420
I created a custom field of type query. It works just fine. However, if you go into the administration section, click the community builder menu, proceed to user management and then click the "New" button, it returns this error:

Error: 1064 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 '[user_id]' at line 1 SQL=SELECT `payment_status` FROM `abca_cbsubs_payments` WHERE `item_name` LIKE '%2014%' and `for_user_id` = [user_id]

The SQL syntax is correct and works just fine for returning the results that I am looking for in their profile. Therefore, I know that it isn't the syntax. Except that [user_id] is a CB variable, so maybe it doesn't know how to handle it when starting from scratch.

Some more information: It is a field type of Query. The SQL query is exactly as listed above.
There is no pre-filled value.
Required: NO
Show on Profile: Yes on 1 line
Display field title in profile: Yes
Searchable: No
User Read Only?: Yes
Show at Registration?: No
Published: Yes

Please Log in to join the conversation.

10 years 6 months ago - 10 years 6 months ago #234611 by krileon
Replied by krileon on topic SQL Syntax Error: 1604
You need to use quotes for substitution values. They always return a string and adding a string straight to a query is invalid SQL. Your query should be as follows.

SELECT `payment_status` FROM `#__cbsubs_payments` WHERE `item_name` LIKE '%2014%' AND `for_user_id` = '[user_id]'


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

10 years 6 months ago #234615 by don5420
Replied by don5420 on topic SQL Syntax Error: 1604
Doesn't work. If I do that the error becomes:

Error: 1054 Unknown column '[user_id]' in 'where clause' SQL=SELECT `payment_status` FROM `abca_cbsubs_payments` WHERE `item_name` LIKE '%2014%' and `for_user_id` = `[user_id]`

Please Log in to join the conversation.

10 years 6 months ago - 10 years 6 months ago #234617 by krileon
Replied by krileon on topic SQL Syntax Error: 1604
Please read my reply previous carefully. You need to use single quotes ( ' ). Your error has apostrophes ( ` ). You must use single or double quotes for values. Apostrophes are only for table names and column names.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

10 years 6 months ago #234619 by don5420
Replied by don5420 on topic SQL Syntax Error: 1604
You are correct. My mistake. It is working now. Strange that it worked to produce the information I needed in their profile without the quotes.

Thanks and mark this as solved!
The following user(s) said Thank You: krileon

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.225 seconds

Facebook Twitter LinkedIn