469,315 Members | 1,573 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

insert the values into the database using python.

8
Good Morning All,

I'm doing a small application using python and MySQL. I'm connecting the database and also creating a table using python application. But, I cannot Insert the values into the table. Can anyone help me to insert the values into the table.
I use the command to insert the values are as follows:

"Insert into custreg (First_Name,Middle_Name,Last_Name,Month,Day,Year,G ender,Address,City,Pin,State,Phone) values ('&fn','&mn','&ln','&month','&day','&year','&gende r','&add','&city','&pin','&state','&phone')"
Advance Thanks for helping me...
Warm Regards,

Srinivas
Mar 11 '09 #1
1 5229
bvdet
2,851 Expert Mod 2GB
I have never used MySQLdb, but after looking at some online documentation for a few minutes, I think your code should look like this:
Expand|Select|Wrap|Line Numbers
  1. import MySQLdb
  2. db = MySQLdb.connect(passwd="something",db="whatever")
  3. c = db.cursor()
  4. c.execute(
  5.     """INSERT INTO custreg (First_Name,Middle_Name,Last_Name,Month,Day,
  6.     Year,Gender,Address,City,Pin,State,Phone)
  7.     VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)""",
  8.     (fn,mn,ln,month,day,year,gender,add,city,pin,state,phone))
Note that last tuple must be valid Python identifiers.
Mar 11 '09 #2

Post your reply

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

Similar topics

11 posts views Thread by grumfish | last post: by
6 posts views Thread by 3c273 | last post: by
10 posts views Thread by Python_it | last post: by
3 posts views Thread by David Mitchell | last post: by
16 posts views Thread by Philip Boonzaaier | last post: by
7 posts views Thread by David Bear | last post: by
1 post views Thread by CARIGAR | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.