首页 > 解决方案 > 从用户输入将数据插入mysql

问题描述

如果假设有另一列名为“age”并且我在两列中插入数据,则以下语法非常有效。但在这种情况下,它显示语法错误。所以我假设这里会使用稍微不同的语法?

db=mysql.connector.connect(host="localhost",user="root",password='',database="cs")
c=db.cursor()
c.execute("create table if not exists leaderboards(idn int auto_increment primary key, name varchar(30))")

nm=str(input("enter your name"))
    
c.execute("insert into leaderboards(name) values(%s)",(nm))
db.commit()

c.close()
db.close()


标签: pythonmysql

解决方案


推荐阅读