Skip to Content Skip to Menu

🎃 Happy Halloween! Treat yourself with an awesome discount on memberships! Get 20% off now with code SPOOKY-2024!

[SOLVED] How to refer to a registration field in a Dblookup query

  • zandar
  • zandar
  • OFFLINE
  • Posts: 7
  • Thanks: 2
  • Karma: 0
11 years 4 months ago - 11 years 3 months ago #229344 by zandar
I whish to allow a user to register on my site only if his/her firstname, lastname and a predefined code ALL match those stored in a table.
I have defined a Dblookup field with the following SQL query:
Code:
SELECT `codusl` FROM `customers` WHERE `uslcode` = '390BB952' AND `userid` is null AND `surname` = `[lastname]` AND `name` = `[firstname]`
That doesn't work, I suppose, because the reference to the "LASTNAME" and "FISRTNAME" fields' value of the registration form is in the wrong syntax, but I can't figure out how to fix it.
If I take out the reference to firstname and lastname, the query does work and the registration completes successfully.

Could someone help me?
Last edit: 11 years 3 months ago by krileon.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48465
  • Thanks: 8280
  • Karma: 1443
11 years 4 months ago #229350 by krileon
You've the wrong quotes around fist name and last name. You're declaring the text as columns instead of as values. The below should work.
Code:
SELECT `codusl` FROM `customers` WHERE `uslcode` = '390BB952' AND `userid` IS NULL AND `surname` = '[lastname]' AND `name` = '[firstname]'


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 or Create an account to join the conversation.

  • zandar
  • zandar
  • OFFLINE
  • Posts: 7
  • Thanks: 2
  • Karma: 0
11 years 4 months ago - 11 years 4 months ago #229353 by zandar
Thank you Krileon for your help.
Now the SQL error is gone, but the query fails (returns the message: "invalid code") even if the value entered in the three fields on the registration form all exactly matches the values stored in the table.

Some suggestions?

Thank you.
Last edit: 11 years 4 months ago by zandar.
The following user(s) said Thank You: krileon

Please Log in or Create an account to join the conversation.

  • zandar
  • zandar
  • OFFLINE
  • Posts: 7
  • Thanks: 2
  • Karma: 0
11 years 4 months ago - 11 years 4 months ago #229468 by zandar
Sorry to bother you again but I'm still unable to get the query working with variables pointing to registration form's field (such as "lastname" and "firstname").


I need to verify that all three fields (uslcode, lastname and firstname) in the registration form do match with the corresponding fields in the table I'm checking.
Changing the quotes from ` ` to ' ' around the field name in the query has corrected the syntax but the it retrieves no rows, so raising the "invalid code" error.

The query does work (and the registration process ends successfully) if I hard type the absolute values of fields "lastname" and "firstname" but not if I refer to them with a variable (like '[lastname]').

Could you show me how to correctly refer to the registration form's fields in order to get their value in the query?

Any help would be much appreciated.
Last edit: 11 years 4 months ago by zandar.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48465
  • Thanks: 8280
  • Karma: 1443
11 years 4 months ago #229493 by krileon

Could you show me how to correctly refer to the registration form's fields in order to get their value in the query?

I already have in my previous post, but you need to have the first and lastname fields available on registration.

To have a working query you need to build it and test it directly on your database then add your substitutions in. You can find more information on substitutions in the below tutorial.

www.joomlapolis.com/support/tutorials/107-use-cases/18353-using-substitutions-throughout-cb


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 or Create an account to join the conversation.

  • zandar
  • zandar
  • OFFLINE
  • Posts: 7
  • Thanks: 2
  • Karma: 0
11 years 4 months ago #229538 by zandar
Obviously I had already checked in phpMyAdmin the query's validity before bothering you with a dumb question...
The query DOES work as expected with values hard-typed in it:

and, as previously said, the registration process ends successfully in that case, but it fails when using substitutions.
You say

you need to have the first and lastname fields available on registration

The registration form does show those fields: beyond that what does it mean "having them available on registration"?


Could you show me exactly how you'd rewrite the query in the "SQL query check" box in the DB lookup field definition form?

Thank you for your patience and support.

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum