victorsubervi at gmail.com
Thu Sep 24 17:01:12 CEST 2009
On Wed, Sep 23, 2009 at 9:13 PM, BJ Swope <bigblueswope at gmail.com> wrote:
> What is your code not doing?
> Are you winding up with duplicate data in the DB?
> Is your web browser re-submitting the form with the same data if you
> refresh the screen?
> Is your web browser pre-filling the fields of the form due to caching?
> I don't understand what's not working
> On Wed, Sep 23, 2009 at 12:40 PM, Victor Subervi <victorsubervi at gmail.com>wrote:
>> I've been trying the hidden field, but the problem is that when I set the
>> variable flag, it stays in memory. I would rather just pass a var like I've
>> been trying, but I don't think it's possible. Any ideas? Is a session cookie
>> the only way? Here's more simplified code:
>> import cgitb; cgitb.enable()
>> import cgi
>> import sys,os
>> import MySQLdb
>> import string, re
>> def client():
>> form = cgi.FieldStorage()
>> client = string.replace(string.replace(form.getfirst('client', ''), "'",
>> '''), '"', '"')
>> flag = form.getfirst('flag', '')
>> print "Content-Type: text/html"
>> print """
>> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "
>> <head xmlns="http://www.w3.org/1999/xhtml">
>> if flag == '':
>> print """
>> <form method="post" action="client.py">
>> Company Name: <input type='text' value='' size='20' maxlength='100'
>> name='client' /><br />
>> <input type='hidden' name='flag' value='y' />
>> <div align='center'>
>> <input type='submit' value=' Send ' />
>> host = 'h'
>> db = 'db'
>> user = 'u'
>> passwd = '1'
>> database = MySQLdb.connect(host, user, passwd, db)
>> cursor = database.cursor()
>> cursor.execute('insert into companies (client);' % (client))
>> print '</body></html>'
>> On Tue, Sep 22, 2009 at 1:43 PM, Dennis Lee Bieber <wlfraed at ix.netcom.com
>> > wrote:
>>> On Tue, 22 Sep 2009 12:50:31 -0400, Victor Subervi
>>> <victorsubervi at gmail.com> declaimed the following in
>>> > Well it's Web stuff, sure, but it's written in python :) The code
>>> > The problem is that I haven't figured out how to tell the program that
>>> > user has entered data and to clear the cache of that data so that it's
>>> > re-entered. How do I do that?
>>> Remember, HTTP is a stateless protocol. EACH submission is
>>> considered a totally new transaction with no memory of the previous
>>> Possible solutions...
>>> * Use a session cookie that identifies what phase in the multistep
>>> processing you are in...
>>> * Use a hidden field in the form that defaults to, say "False",
>>> you first display the form, but then gets set to "True" during the first
>>> response process (and is then sent back out with "True" so the second
>>> response takes a different branch).
>>> Wulfraed Dennis Lee Bieber KD6MOG
>>> wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/<http://wlfraed.home.netcom.com/>
> To argue that honorable conduct is only required against an honorable enemy
> degrades the Americans who must carry out the orders. -- Charles Krulak,
> Former Commandant of the Marine Corps
> We are all slave to our own paradigm. -- Joshua Williams
> If the letters PhD appear after a person's name, that person will remain
> outdoors even after it's started raining. -- Jeff Kay
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list