【问题标题】:I cant put user output to put it in mysql workbench whats wrong in this.Help me guys我不能把用户输出放到mysql工作台中,这有什么问题。帮帮我
【发布时间】:2022-01-20 11:09:44
【问题描述】:

我无法将用户输出放到 mysql 工作台中,这有什么问题。帮帮我。

def amount_ofmoney(self):
    id_ask = int(input("Enter ur acc id:"))
    result =self.checkidname(id_ask)
    while result==False:
      print("Invaild id")
    else:
      amount = int(input("Enter the amount of money u wan to put in ur acc:"))
      if amount > 100000:
        print("Sorry choose less amount") 
      else:
        sql = "insert into bank_table(money_amount)  values(%s)"
        val = (amount)
        self.mycursor.execute(sql,val)
        self.mydb.commit()

错误是这样的

mysql.connector.errors.ProgrammingError: 1064 (42000): 你的 SQL 语法有错误;检查与您的 MySQL 服务器相对应的手册 在第 1 行的 '%s)' 附近使用正确语法的版本

【问题讨论】:

    标签: python mysql sql database


    【解决方案1】:

    尝试在 'table' 和 '(' 之间以及 'values' 和 '(' 之间添加一个空格。

    sql = "插入bank_table (money_amount) 值(%s)"

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-28
      • 1970-01-01
      相关资源
      最近更新 更多