By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,699 Members | 1,228 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,699 IT Pros & Developers. It's quick & easy.

Insert data quickly into database from GUI

P: 1
Expand|Select|Wrap|Line Numbers
  1. def on_button1_clicked(self, widget, data=None):
  2.         con = MySQLdb.connect('localhost', 'root', 'warriors', 'reg');
  3.         with con:
  4.             cur = con.cursor()
  5.             sql_st="INSERT INTO regg (username, password) VALUES ('ra','%s')"
  6.             cur.execute(sql_st)
  7.             print "It has been inserted successfully "



here the values ra and %s is only inserting in database,but i need a coding for insert statement where the user types in gui application and click insert option tht data only should update..
Dec 19 '12 #1
Share this Question
Share on Google+
3 Replies

bvdet
Expert Mod 2.5K+
P: 2,851
You missed an important component of the assignment to sql_st:
Expand|Select|Wrap|Line Numbers
  1. sql_st="INSERT INTO regg (username, password) VALUES ('ra','%s')" % (data)
Dec 19 '12 #2

Rabbit
Expert Mod 10K+
P: 12,441
If you don't want to insert, change your SQL to an insert statement.

If what you actually mean is to do a conditional insert/update depending on if the data is already there. Use an if statement to run different SQL.
Dec 19 '12 #3

Expert 100+
P: 626
You also have to commit for the changes to take place unless auto commit is turned on.
Dec 19 '12 #4

Post your reply

Sign in to post your reply or Sign up for a free account.