I\'m getting the exception _mysql_exceptions.ProgrammingError: not all arguments converted during string formatting
when calling this function to insert a stude
The correct way of writing prepared statements is the following:
def create_student(surname, forename, dob, address, phone, gender, tutor, email):
cursor = mysql.connection.cursor()
cursor.execute('''
INSERT INTO students(surname, forename, dob, address, phone, gender, tutor, email)
VALUES(%s, %s, %s, %s, %s, %s, %s, %s)''', (surname, forename, dob, address, phone, gender, tutor, email))
mysql.connection.commit()
The error comes from the fact that the mysql module does not find where to put the paramters you are giving it, because it does not interpret the questions marks as placeholders, and thus is producing an error telling you that _mysql_exceptions.ProgrammingError: not all arguments converted during string formatting
, which in human language, means it could not fit your aguments in the format string.