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
1 5370 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: - import MySQLdb
-
db = MySQLdb.connect(passwd="something",db="whatever")
-
c = db.cursor()
-
c.execute(
-
"""INSERT INTO custreg (First_Name,Middle_Name,Last_Name,Month,Day,
-
Year,Gender,Address,City,Pin,State,Phone)
-
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)""",
-
(fn,mn,ln,month,day,year,gender,add,city,pin,state,phone))
Note that last tuple must be valid Python identifiers.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Jack |
last post by:
I have a text file of data in a file (add2db.txt) where the entries are
already entered on separate lines in the following form:
INSERT INTO `reviews` VALUES("", "Tony's", "Lunch", "Great...
|
by: grumfish |
last post by:
I'm trying to add a row to a MySQL table using insert. Here is the code:
connection = MySQLdb.connect(host="localhost", user="root", passwd="pw",
db="japanese")
cursor = connection.cursor()...
|
by: 3c273 |
last post by:
Hello,
I have a really simple Access database table with a format similar to this:
CustomerName - ProductOrdered - QtyOrdered
I have a CSV file with the appropriate values as follows:...
|
by: serge |
last post by:
I have a scenario where two tables are in a One-to-Many relationship
and I need to move the data from the Many table to the One table so
that it becomes a One-to-One relationship.
I need to...
|
by: Python_it |
last post by:
Python 2.4
MySQL-python.exe-1.2.0.win32-py2.4.zip
How can I insert a NULL value in a table (MySQL-database).
I can't set a var to NULL? Or is there a other possibility?
My var must be variable...
|
by: David Mitchell |
last post by:
Hello,
I am a complete beginner with Python. I've managed to get mod_python up and
running with Apache2 and I'm trying to a simple insert into a table in a
MySQL database.
I'm using the...
|
by: Philip Boonzaaier |
last post by:
I want to be able to generate SQL statements that will go through a list of
data, effectively row by row, enquire on the database if this exists in the
selected table- If it exists, then the colums...
|
by: David Bear |
last post by:
I have a dictionary that contains a row of data intended for a data base.
The dictionary keys are the field names. The values are the values to be
inserted.
I am looking for a good pythonic...
|
by: Ben |
last post by:
I don't know whether anyone can help, but I have an odd problem. I have
a PSP (Spyce) script that makes many calls to populate a database. They
all work without any problem except for one...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |