Hello!
I have this funtion to delete a record from a MySQL table:

def delUser(): #Delete user
	#Ask for user to delete
	Username = raw_input('Which user would you like to delete? ')
	#Delete user
	delUser = '''DELETE FROM Users WHERE Username = %s'''
	cursor.execute(delUser,(Username))
	db.commit()

The problem is that it makes nothing if the selected user (Username) does not exist. In case the user does not exist, I would like the function to print an error (something like "User does not exist. Try again", and go back to the raw input line. How can I do it?
Cheers!

Dani

You can do a select first to see if it exits, and delete thereafter if exists, or give error message if it doesn't.

if you are using mysqldb, the cursor object should contain some information about the query/delete, check it out

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.