Ask coding questions

← Back to all posts
How to store a users input into a database?
BartKeijzer

So, I want to store a users input, into a database, but I really don't know how to.
Could anyone please help me with it?

Voters
BartKeijzer
Comments
hotnewtop
VulcanWM

What language?

BartKeijzer

Python

@VulcanWM

BartKeijzer

Since you made a login and signup page, on your profile page, I think you know alot about it

@VulcanWM

VulcanWM

If you want to use replit db you can do the code below

from replit import db
db[‘key_name’] = ‘value’
note that replit db doesn’t work in the console and you should do it in web apps like flask
@BartKeijzer

BartKeijzer

and how to add a users input to that db?

@VulcanWM

VulcanWM

like flask or just normal input? @BartKeijzer

BartKeijzer

what is flask?
i mean just like test = input('anything')
@VulcanWM

VulcanWM

Flask is a way to make websites where other people can use the repl with the database without any problems
When you do normal inputs (it is in your console) so the database will only work for you
But if you want to do normal input, use the code below

from replit import db
name = input(“What is your name?”)
data = input(“What do you want to save?”)
db[name] = data

@BartKeijzer

BartKeijzer

so will that work?
can the replit owner view the db also?

@VulcanWM

BartKeijzer
BartKeijzer
VulcanWM

It will work for you
There is some website to view your data apparently
You can do some code to view it tho @BartKeijzer

VulcanWM

To view all your data do
for i in db.keys():
print(f”{str(i)}: {str(db[i])}”)

@BartKeijzer

BartKeijzer

and where to put what db i want to view?

@VulcanWM

BartKeijzer

not working for me

@VulcanWM

VulcanWM

What isn’t working? @BartKeijzer

BartKeijzer

it says an error

@VulcanWM

VulcanWM

What error and which code? @BartKeijzer