DB Saving Issues

Hi! I’m trying to create kind of a virtual bank. The coins are owned after clicks on #button4 of the adverts. The code is:


#button5 is another story, but the rest of the code is about the coins. They are saved in to “moedas” column with the connection of the dynamicDataset. The problem is this message error that never goes away

I already checked the permissions:


Ler e escrever = read and write (sorry about the poor english, I’m brazilian)

“qualquer pessoa” = anyone (sorry about the poor english, I’m brazilian)

PLEEEEASE HELP MEEEE! How can I finish with this error???

(I’m just starting with wix code, so please explain in dumb language hahahahha)

I’m guessing that it is probably the top forum thread that will help you as you’ve got coins amount in your dataset which probably should be listed as numbers and not text.

Thank you very much for your answer! I will see the links right now. And the type of “moedas” is a number, as you said:


número=number

The data that I’m generating with my code is a number. Correct??

@bellecampos

You’ve got count +1 in your code, so the dataset field value would be as numbers and not text, the same applies to your user input element too, that needs to be number value too.

This means that you might have a text type input form element on your page but that is actually a number type in your Data Collection. You must make sure that all types in your form is made compatible with the field types in your Data Collection. When you have fixed that it will work.

Also, make sure that you have an onReady at the start of your code so that the page itself loads up and is ready, currently you only have the dataset itself getting ready, make sure that you have put the onclick function on button 4 properties too.

Your currentItem line maybe needs a ; at the end too and take off the {} on the show button 5 line.

Chwck the api page for more info:
https://www.wix.com/code/reference/wix-dataset.DynamicDataset.html

@bellecampos

It looks like you are following this tutorial, sort of:

So notice the code and make that everything is correct with yours.

$w("#dataset1").onReady(() => {
// get the current item from the dataset
const currentItem = $w("#dataset1").getCurrentItem();

// get the current average rating, number of ratings, and
//total ratings for the current dataset item
const average = currentItem.avg;
const count = currentItem.numRatings;
const total = currentItem.totalRatings;

// get the new rating from the ratings input
const newRating = $w('#ratingsInput1').value;
// calculate the new average rating based on the current
//average and count
const newAverageLong = (total + newRating) / (count +1);
// Round the average rating to 1 decimal point
const newAverageShort = Number.parseFloat(newAverageLong).toFixed(1);

// set the dataset fields to the new average, total
// ratings, and number of ratings
$w('#dataset1').setFieldValues({
'avg': newAverageShort,
'totalRatings': total + newRating,
'numRatings': (count + 1)
});

// save the dataset fields to the collection
$w('#dataset1').save()
.catch((err) => {
console.log('could not save new rating');
});
});

@givemeawhisky Tnx!! I’ll follow all your hints! And yes, I’m following this tutorial :slight_smile: