MySQL Forums
Forum List  »  Connector/Python

Problem inserting data from form
Posted by: douglas_m2
Date: November 01, 2006 08:54PM

Hello there,

OK I've tried everything I can think of with this one.

I'm trying to insert data from a form to MySQL using Python. My code is as follows:

#!c:\Python23\python
import MySQLdb
import cgi
import sys

http = "Content-type:text/html\n"
title = "jokes"
head = "<html>\n<head>\n<title>"+title+"\n</head>\n<body>\n"
foot = "</body>\n</html>\n"

print http

form = cgi.fieldstorage()

connection = MySQLdb.connect( "localhost", "root", "Sibelius", "jokes" )
cursor = connection.cursor()
cursor.execute=( "INSERT INTO entries (Joke, User) VALUES ('%s','%s')" % (form['joke'].value, form['user'].value) );

print foot

As I said, I've tried absolutley everything. It appears to process the code fine, but every time I go to the display page for the table it appears like nothing has been added. My database is called jokes and my table is called entries. My columns are called Joke and User. I'd be very grateful for some help

Thanks

Douglas

Options: ReplyQuote


Subject
Written By
Posted
Problem inserting data from form
November 01, 2006 08:54PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.