简体   繁体   English

从 MySQL 数据库中的文本区域插入文本(Python/Flask)

[英]Insert text from a Text Area in a MySQL DB (Python/Flask)

I want to code a small message feed for my homepage.我想为我的主页编写一个小消息提要。 I want to send a text from a textarea to my Database this is my html template:我想将文本区域中的文本发送到我的数据库,这是我的 html 模板:

 {% extends 'layout.html'%}

 {% block body%}

   <form action="/feed" method="post">
   <table>
     <tr>
       <td><textarea name="feedtext" id="feedtext" placeholder="Type message here!" rows="4" cols="53"></textarea></td>
     </tr>
     <tr>
       <td><button style="width: 65%;" "submit"\>Send</button></td>
     </tr>
   </table>
   </form>

{% endblock %}

now my problem is the python part.现在我的问题是 python 部分。 I try anything but I don't get the right code.我尝试任何事情,但我没有得到正确的代码。

this is my python code now:这是我现在的python代码:

 @app.route('/feed', methods=['POST'])
 def feed():
     try:
         conn = mysql.connect()
         cursor = conn.cursor()
         feedtxt = request.form['feedtext']

         cursor.execute('INSERT INTO nachrichten (Vorname, Nachname, Nachricht) VALUES(%);', (feedtxt))

     finally:
         cursor.close()
         conn.close()

Welcome .欢迎

Can not make out " I try anything but I don't get the right code ".无法弄清楚“我尝试了任何东西,但我没有得到正确的代码”。

Anyway, out of the columns反正列外

(Vorname, Nachname, Nachricht) (Vorname, Nachname, Nachricht)

it seems only the Nachricht gets the value of (feedtxt).似乎只有 Nachricht 获得 (feedtxt) 的值。

Try giving 3 items within VALUES尝试在VALUES 中提供 3 个项目

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM