Extract a specific field from a database via a query

Question:

Hello everybody,

I would like to know if it was possible via a wix code to extract a specific data from a database:

I haven’t found a solution so far.

For example, I have a database with discount codes.

On my “cart” page, the customers enter their code which was sent to them by email.

If this code is present in the “discount codes” database: it extracts the reduction percentage corresponding to the code entered, otherwise, an error message.

How to verify if the code exists and how to display the corresponding percentage please?

Thans a lot.

Product:
wix editor

What are you trying to achieve:

extracting data from a database cooresponding to a field on the “Cart” page

Wix has built-in functionality for discounts, so you don’t need to reinvent the wheel

In any case, to check for exact matches of a value:

wixData.query('collectionName').eq('fieldName', value).find()

If you do end up creating this on your own note that a guest should never have any access to this database, or they’ll be able to read it freely
Instead, you’ll need to implement this query on the backend and call it using a web module

1 Like

Hi

Thank you for this answer. I succeeded to do it thanks to your help.
I know that Wix has built-in functionality for discounts, but it dosen’t match with my personal “cart”. So I created my own discount database.

Thank you…

You are very welcome :slight_smile:

1 Like