首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >尝试将用户输入插入SQL表时出错

尝试将用户输入插入SQL表时出错
EN

Stack Overflow用户
提问于 2019-11-29 05:58:37
回答 1查看 18关注 0票数 1

我遇到了问题,每当我试图运行下面的代码,选择语句2来,插入一个工具并放置一个随机的工具名,我就会得到错误消息:ProgrammingError(‘列“插入工具’不存在\n行1: insert tools(tool_name,rental_days)值(@insertTool,'2')

以下是代码:

代码语言:javascript
复制
if Menu == "2":
  cursor = connection.cursor()
  InsertTool = raw_input("Please insert the tool that you want to add.\n")
  insert_tool = """insert into tools(tool_name, rental_days) values(@InsertTool, '2')"""  
  try:
     cursor.execute( insert_tool);
     connection.commit();
     print("Tool is succesfully inserted!")

  except Exception as e:
     connection.rollback();
     print("Exception Occured : ",e)
  connection.close(); 
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-11-29 06:05:25

尝尝这个。

代码语言:javascript
复制
if Menu == "2":
  cursor = connection.cursor()
  InsertTool = raw_input("Please insert the tool that you want to add.\n")
  insert_tool = """insert into tools(tool_name, rental_days) values(%s, %s)"""
  val = (InsertTool, "2")
  try:
     cursor.execute(insert_tool, val);
     connection.commit();
     print("Tool is succesfully inserted!")

  except Exception as e:
     connection.rollback();
     print("Exception Occured : ",e)
  connection.close();
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59099440

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档