We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see ourdocumentation.
There was an error while loading.Please reload this page.
1 parentc846ae1 commitfdb8a78Copy full SHA for fdb8a78
PythonProject/form.py
@@ -1,38 +1 @@
1
-fromflaskimportFlask,render_template,request
2
-importsqlite3
3
4
-app=Flask(__name__)
5
-
6
-# Database setup (creates the table if it doesn't exist)
7
-conn=sqlite3.connect('mydatabase.db')# Replace 'mydatabase.db' with your desired name
8
-cursor=conn.cursor()
9
-cursor.execute('''
10
- CREATE TABLE IF NOT EXISTS entries (
11
- id INTEGER PRIMARY KEY AUTOINCREMENT,
12
- name TEXT,
13
- email TEXT
14
- )
15
-''')
16
-conn.commit()
17
-conn.close()
18
19
20
-@app.route('/',methods=['GET','POST'])
21
-defindex():
22
-ifrequest.method=='POST':
23
-name=request.form['name']
24
-email=request.form['email']
25
26
-conn=sqlite3.connect('mydatabase.db')
27
28
-cursor.execute("INSERT INTO entries (name, email) VALUES (?, ?)", (name,email))
29
30
31
32
-return"Data submitted successfully!"# You might want a more sophisticated response
33
34
-returnrender_template('form.html')
35
36
37
-if__name__=='__main__':
38
-app.run(debug=True)