hello!
I would like to check that both input matches with my database element.
For example i have an input field for name and birthday each. and in my database there are 2 columns which is name and birthday. i want to enter a name and the corresponding birthday of the person in each user input field to confirm that it is the same person.
how should i go about doing this?
thank you so much for your help in advance
Hi tpmp2017,
The way to approach something like this is to perform a database query to read one of the values based on the other. For instance, you can query the birthday based on the name and compare to the inputs. Something like this -
import wixData from 'wix-data';
export function BUTTON_onClick(event) {
let name = $w('#INPUT_NAME').value;
wixData.query('MY_COLLECTION')
.eq('NAME_FIELD', name)
.find()
.then(res => {
if (res.length === 0) {
// name not found in DB
}
else if (res.items[0].birthday === $w('#INPUT_BIRTHDAY').value) {
// same birthday value
}
else {
// not the same birthday value
}
})
}
Note that you will need to replace the upper case identifier with the input ids, collection name and setup the right trigger for the check - in this case it is a button click.
ahh omg ok thank you so much! i was quite close heheh just missing a few things!! thank you so much!!
Hello Yoav, so the code works fine in preview but when it is published it does not work… even after ive moved all the data in the database into the live box…
Dear Yoav,
Hello,
Please can you tell me how can I redirect user to an ID page if both inputs matche with my database element?
Thank you in advance!
Arman.