Insert data quickly into database from GUI

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • waran
    New Member
    • Dec 2012
    • 1

    Insert data quickly into database from GUI

    Code:
    def on_button1_clicked(self, widget, data=None):
            con = MySQLdb.connect('localhost', 'root', 'warriors', 'reg');
            with con:
                cur = con.cursor()
                sql_st="INSERT INTO regg (username, password) VALUES ('ra','%s')"
                cur.execute(sql_st)
                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..
    Last edited by bvdet; Dec 19 '12, 03:13 PM. Reason: Add code tags
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    You missed an important component of the assignment to sql_st:
    Code:
    sql_st="INSERT INTO regg (username, password) VALUES ('ra','%s')" % (data)

    Comment

    • Rabbit
      Recognized Expert MVP
      • Jan 2007
      • 12517

      #3
      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.

      Comment

      • dwblas
        Recognized Expert Contributor
        • May 2008
        • 626

        #4
        You also have to commit for the changes to take place unless auto commit is turned on.

        Comment

        Working...