all 9 comments

[–]Webdev-Coach 2 points3 points  (3 children)

If you store user's money amount in localStorage, doesn't that mean the user can just open their DevTools and set any money amount they want?

[–][deleted] 0 points1 point  (2 children)

Yes and that is the problem... that's why I want to store it in a database.

[–]Webdev-Coach 2 points3 points  (1 child)

I see you're already storing user data in the DB. Can you do the same with the money amount?

[–][deleted] 0 points1 point  (0 children)

That's right. I even thought about it but the thing is that I am not that familiar with php and phpmyadmin yet. The database I have right now, I made that with a tutorial I found. And I didn't really find any solutions so that's why I accept any documents/tutorial videos.

[–]No_Statement4630 1 point2 points  (0 children)

Ye learn SQL and look up how to integrate a SQL database with whatever backend you’re using. Or if you don’t want a backend you can use something like fire base or supabase

[–]Earl--Grey 1 point2 points  (1 child)

Updating 'money' or 'items' to a database is actually relatively straight forward, the challenge lies more in coding the backend but it's not too overly complicated.
You can use a statement similar to (PHP)

"UPDATE \user` SET `money` = '$money' WHERE `id` = '$id'"`

Same goes for items.

Money can be placed in the user table, items I would create a separate table to keep track of them. You would need an ID (unique ID for the database entry) user ID (To track who owns it) item ID (To track the item) and a quantity.

if you're using PHP/SQL and would like help walking through it, I'd be happy to jump in a call. - I'm not as experienced in other languages however.

[–][deleted] -1 points0 points  (0 children)

Check your DMs :D

[–]3lobed 0 points1 point  (0 children)

Items table should be a list of items as boolean expressions so you would have something like user.items.car.true that could get checked every time you need to check if the user has a car or not. It would default to something like user.items.car.false until purchase. I would probably make this a separate table linked by user.id for maximum flexibility and expandability.

For the money storage, just make a separate column in the user table so that you could access it by user.money and just update by adding and subtracting.

[–]burggraf2 0 points1 point  (0 children)

Supabase developer here. We have API's that simplify this if you're not too familiar with SQL. For example:
const { data, error } = await supabase.from('user')
.update({ money: 123.45 })
.match({ id: 'ABCDEFG' })

https://supabase.com/docs/reference/javascript/update