Skip to content

Commit fdb8a78

Browse files
authored
Update form.py
1 parent c846ae1 commit fdb8a78

File tree

1 file changed

+0
-37
lines changed

1 file changed

+0
-37
lines changed

PythonProject/form.py

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1 @@
1-
from flask import Flask, render_template, request
2-
import sqlite3
31

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-
def index():
22-
if request.method == 'POST':
23-
name = request.form['name']
24-
email = request.form['email']
25-
26-
conn = sqlite3.connect('mydatabase.db')
27-
cursor = conn.cursor()
28-
cursor.execute("INSERT INTO entries (name, email) VALUES (?, ?)", (name, email))
29-
conn.commit()
30-
conn.close()
31-
32-
return "Data submitted successfully!" # You might want a more sophisticated response
33-
34-
return render_template('form.html')
35-
36-
37-
if __name__ == '__main__':
38-
app.run(debug=True)

0 commit comments

Comments
 (0)