Quantcast
Channel: Active questions tagged row - Stack Overflow
Viewing all articles
Browse latest Browse all 445

I am trying to add variables into a new DB row using Python. The code I have written gets no error but doesn't write the new row. into the table? [duplicate]

$
0
0

Connection to database

import datetimeimport pymysqlconn = pymysql.connect(   host='localhost',   user='XXXX',   #password=,   db='golf_db',   charset='utf8mb4',   cursorclass=pymysql.cursors.DictCursor)

Define variables for the table row

lastname="Doe"firstname="John"front9=8back9=8birthday=datetime.date(2025,1,31)

SQL statements to add row

with conn.cursor() as cursor:    sql = "INSERT INTO `Golfers` (`Last_Name`, `First_Name`, `F_Handicap`, `B_Handicap`, `B_Date`) VALUES (%(lastname)s, %(firstname)s, %(front9)s, %(back9)s, %(birthday)s)"    conn.commit()

Check to see if variables were properly defined

    print(firstname, lastname, front9, back9, birthday)

Viewing all articles
Browse latest Browse all 445

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>