470,873 Members | 1,858 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,873 developers. It's quick & easy.

Insert data quickly into database from GUI

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
3 2045
bvdet
2,851 Expert Mod 2GB
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
12,516 Expert Mod 8TB
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
dwblas
626 Expert 512MB
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.

Similar topics

3 posts views Thread by c676228 | last post: by
1 post views Thread by Doc11 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.