简体   繁体   English

如何使用 Python 将 HTML 从 info 传递到 MySQL 数据库?

[英]How to pass HTML from info to MySQL database using Python?

I am using Pyhton and Flask and I am trying to pass the information from HTML form to MySQL db.我正在使用 Pyhton 和 Flask,我正在尝试将 HTML 表单中的信息传递给 MySQL db。 I am connected to the database and I know that it works because I tried it via terminal but I am not sure how to pass information from the HTML form?.我已连接到数据库,我知道它可以工作,因为我通过终端尝试过,但我不确定如何从 HTML 表单传递信息? Can someone advise on this.有人可以就此提出建议。 Thanks in advance!提前致谢! SuYan苏燕

@app.route("/sign-up", methods=["POST"])
def signup():
    title = "Sign-up"
    return render_template("signup.html", title=title)
    def signup(): 
        name = request.form['name'] 
        age = request.form['age'] 
        pas = request.form['signup-button']
        mycursor.execute("INSERT INTO person (name, age) VALUES (%s,%s)", (name, age))
db.commit()
@app.route("/sign-up", methods=["GET","POST"])
def signup():
    if request.method == "POST":
        name = request.form['name'] 
        age = request.form['age'] 
        pas = request.form['signup-button']
        mycursor.execute("INSERT INTO person (name, age) VALUES (%s,%s)", (name, age))
        db.commit()
    title = "Sign-up"
    return render_template("signup.html", title=title)

Hey Su Yan, Use this and let me know if this works or error persists.嘿苏燕,使用这个,让我知道这是否有效或错误仍然存在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 python 执行来自 mysql 数据库的信息的用户输入 - How to execute users input from info from mysql database using python 如何使用 QWebChannel 将信息从 JS 传递到 Python - How to pass info from JS to Python using QWebChannel 如何使用python从html标签中提取突出显示的信息? - How to extract the highlighted info from the html tags using python? 如何使用 python 传递两个或多个列表并将其存储到 mysql 数据库 - How to pass two or more lists by using python and store it to mysql database 如何使用python从mysql数据库中删除 - How to delete from mysql database using python 使用Python将检索到的游标从一个MySQL数据库传递到另一个MySQL数据库 - Pass retrieved cursor from one MySQL database to another MySQL database using Python 使用 Python 将数据从 Html 表单插入到 MySQL 数据库 - Inserting data into from Html form to MySQL Database using Python 如何使用 python django 将 html 表单中的数据插入 MySQL 数据库 - How to insert data from html form into MySQL database using python django 如何将信息从 Python Tkinter 脚本上传到 MySQL 数据库? - How can I upload info from Python Tkinter script to MySQL database? 如何使用 python 将 MySQL 数据库数据输入到 html 表中? - How to input MySQL database data to a html table using python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM