skip to Main Content

that’s it.Im using mysql-connector-python. I can run the commented part successfuly. But the actual part doesn’t work

                querry = "INSERT INTO selectdif (name, score) VALUES (%s, %s)"
                value = ("Sssss", 10)
                cursor.execute(querry)
                
                """sql = "INSERT INTO selectdif (name, score) VALUES (%s, %s)"
                val = [
                    ('Peter', 'Lowstreet 4'),
                    ('Amy', 'Apple st 652'),
                    ('Hannah', 'Mountain 21'),
                    ('Michael', 'Valley 345'),
                    ('Sandy', 'Ocean blvd 2'),
                    ('Betty', 'Green Grass 1'),
                    ('Richard', 'Sky st 331'),
                    ('Susan', 'One way 98'),
                    ('Vicky', 'Yellow Garden 2'),
                    ('Ben', 'Park Lane 38'),
                    ('William', 'Central st 954'),
                    ('Chuck', 'Main Road 989'),
                    ('Viola', 'Sideway 1633')
                    ]

                cursor.executemany(sql, val)"""

I’m pretty sure this is the correct way to insert base on the tutorials I see

EDIT: changing from this:

value = ("Sssss", 10)
            cursor.execute(querry)

to this:

value = ('Sssss', '10')
                cursor.execute(querry, value)

fixed it.

2

Answers


  1. Chosen as BEST ANSWER

    I completely forgot to give value.


  2. While you are trying to insert multiple, please check the value of your ‘score’ column. Probably it should be number. In your code you are passing string. That may be the reason.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search