0

So, I'm not sure how to go about this. I've installed and imported MySQL Connector.

fit=sql.connect(host='localhost',user='root',passwd='xez23%',database='fitnesscentre')

                uID= int(input('Enter user ID: '))
                pwd= input('Enter password: ')
                wgt1=int(input('Enter your weight: '))
                bmi= float(input('Enter BMI: '))
                actlevel= int(input('Enter activity level in minutes: '))
                upd= input('Update? Y/N')
                if upd=='Y':
                    d=fit.cursor()
                    rec1='UPDATE userstats SET weight=%s, BMI=%s, activitylevel=%s WHERE ID=%d; '
                   

What do I do next? This is the table userstats: userstats

2 Answers 2

1

i use this to input:

import mysql.connector

conn = mysql.connector.connect(
   user='root', password='*******', host='127.0.0.1', database='data')

cursor = conn.cursor()


insert_stmt = (
   "insert into datauser(nama_depan,nama_belakang,email,iat,at_hash)"
   "VALUES (%s, %s, %s, %s, %s)"
)
data = ('value', 'value', 'value', value, 'value')

try:
  
   cursor.execute(insert_stmt, data)
   
  
   conn.commit()

except:
  
   conn.rollback()

print("Data inserted")


conn.close()
Sign up to request clarification or add additional context in comments.

Comments

0

What to do next is call execute() on the cursor. The first argument is the SQL string with parameter placeholders. The next argument is a tuple containing the values you want to use for those placeholders, in the same order as the placeholders in the SQL string.

d.exec(rec1, (wgt1, bmi, actlevel, uID,))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.