2

I am trying to do the code as follows to register a player with a given name, but I can't get the argument name to do anything… I thought that %s was the variable to insert a string into a database, but it doesn't seem to work.

import psycopg2

def registerPlayer(name):
    """Registers new player."""
    db = psycopg2.connect("dbname=tournament")
    c = db.cursor()
    c.execute("insert into Players values (%s);")
    db.commit()
    db.close()

registerPlayer("Butter")

When I run it, I get the error message:

ProgrammingError: syntax error at or near "%"    
LINE 1: insert into Players values (%s);
0

1 Answer 1

3

You haven't actually passed the parameter into the execute method.

c.execute("insert into Players values (%s);", (name,))
Sign up to request clarification or add additional context in comments.

1 Comment

I knew I was missing something obvious. Thanks!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.