We're creating a basic MUD and want it to save/load from a MySQL database, as an initial command, we want to have an initial "Do you have a character?" prompt, we have the "no" part sorted out, and it successfully saves to the database. However, I'm having trouble with the "yes" part, more specifically, having it check the DB for a specific entry against user input to make sure it exists, and consequently load the data.
Here's my current code:
global name
name = ''
savename = ("INSERT INTO CharactersDB (ID) VALUES (%s)")
loadname = ("SELECT ID FROM CharactersDB WHERE ID=%s")
def newname():
global name
newchar = raw_input("Do you have a character? (y/n) ")
if newchar == 'y':
login = raw_input("Please enter your Character's name: ")
logincheck = cur.execute(loadname, login)
if login == logincheck:
print "pass"
print "Successfully loaded ", login, "from the database"
else:
print "Sorry, could not find you in the database"
print "Or it just isn't working"
else:
name = raw_input("Please enter a new name: ")
#save new name to the database
cur.execute(savename, name)
print "Name saved, you are now called ", name
db.commit()
return name
newname()
I don't have any errors, it just goes from the first if statement to the second one, saving the "new" name (though no changes are made to the db since the entry already exists)