Ok. Starting over. Here is the script that "generates" the variable "new_passengers_curr_customers":
#!/usr/bin/python import cgitb; cgitb.enable() import cgi import sys,os sys.path.append(os.getcwd()) import MySQLdb from login import login from Curr_Passengers_Table import Curr_Passengers_Table def create_edit_passengers(): print "Content-Type: text/html" print print ''' <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"> <head xmlns="http://www.w3.org/1999/xhtml"> </head> <body> ''' user, passwd, db, host = login() database = MySQLdb.connect(host, user, passwd, db) cursor = database.cursor() form = cgi.FieldStorage() flight = form.getfirst('flight') try: cursor.execute('select c.id, p.name, p.weight, c.first_name, c.middle_name, c.last_name, c.suffix from Passengers p join Customers c where p.flights_id=%s;', flight) passengers = cursor.fetchall() except MySQLdb.ProgrammingError: passengers = [] cursor.execute('select * from Flights where id=%s;', flight) flight_data = cursor.fetchone() print "<b>You have selected flight #%s, departing %s from %s and arriving %s at %s.</b><br /><br />" % (flight_data[0], flight_data[2], flight_data[5], flight_data[3], flight_data[6]) if len(passengers) > 0: print '<form method="post" action="create_edit_passengers3.py">\n' Curr_Passengers_Table(passengers) print "<h2>Add Passengers</h2>" else: print "There are currently no passengers enrolled in this flight. Please enter some." print '<form method="post" action="create_edit_passengers3.py">\n' *** RIGHT HERE! *** print "<input type='text' size='2' maxlength='2' name='new_passengers_curr_customers' /><br />" ^^^^^ *** SEE IT? *** print "<input type='submit' value=' Send ' />" print '</body>\n</html>' cursor.close() create_edit_passengers() Now, here's the form that *should* be able to access that variable: !/usr/bin/python import cgitb; cgitb.enable() import cgi import sys,os sys.path.append(os.getcwd()) import MySQLdb from login import login import fpformat from New_Passengers_Curr_Customers import New_Passengers_Curr_Customers from New_Passengers_Addl_Customers import New_Passengers_Addl_Customers from New_Passenger import New_Passenger form = cgi.FieldStorage() def sortedDictValues(adict): items = adict.items() items.sort() return [value for key, value in items] def create_edit_passengers3(): print "Content-Type: text/html" print print ''' <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"> <head xmlns="http://www.w3.org/1999/xhtml"> </head> <body> ''' user, passwd, db, host = login() database = MySQLdb.connect(host, user, passwd, db) cursor = database.cursor() cursor.execute('select id from Flights;') flights = [itm[0] for itm in cursor] cursor.execute('select id, first_name, middle_name, last_name, suffix from Customers;') customers = cursor.fetchall() try: cursor.execute('select p.id, c.first_name, c.middle_name, c.last_name, c.suffix, c.discount, p.flights_id, p.name, f.price, c.id from Customers c join Passengers p on c.id=p.customer_id join Flights f on p.flights_id=f.id ;') passengers = cursor.fetchall() print '<form method="post" action="create_edit_passengers4.py">\n' start_html = "<table border='2'>\n <tr>\n <td><b>Delete?</b></td>\n <td><b>Flight</b></td>\n <td><b>Name</b></td>\n <td><b>Discount</b></td>\n <td><b>Price</b></td>\n </tr>\n" passengers_html = [] ids = [] i = 0 for passenger in passengers: do_delete = form.getfirst('%s:delete' % passenger[0]) passengers_html, i = New_Passenger(passengers_html, passenger, do_delete, flights, ids, i) printHTML = sortedDictValues(dict(zip(ids, passengers_html))) if len(printHTML) > 0: print start_html for html in printHTML: print html print "</table>" except MySQLdb.ProgrammingError: pass *** NOTE THIS: **** new_passengers_curr_customers = New_Passengers_Curr_Customers(customers, flights) *** THAT LINE **** if new_passengers_curr_customers > 0: print "<input type='submit' value=' Send ' />" print '</body>\n</html>' cursor.close() create_edit_passengers3() See that line that I marked right at the end? So here's that script: #!/usr/bin/python import cgitb; cgitb.enable() import cgi form = cgi.FieldStorage() def New_Passengers_Curr_Customers(customers, flights): *** RIGHT HERE. SEE THIS LINE? WHY DOES IT WORK HERE AND NOT IN THE 2ND SCRIPT IN THIS HERE EMAIL WHERE IT SHOULD WORK???*** new_passengers_curr_customers = int(form.getfirst('new_passengers_curr_customers', 0)) *** THAT LINE ABOVE. RIGHT ABOVE HERE. OK?? *** print "<input type='hidden' name='new_passengers_curr_customers' value='%d' />" % new_passengers_curr_customers if new_passengers_curr_customers > 0: print "<table border='1'>\n" print " <tr>\n <td colspan='2' align='center'><b>From Current Customers</b></td>\n </tr>" print " <tr>\n <td><b>Flight</b></td>\n <td><b>Customer</b></td>\n </tr>" i = 0 while i < new_passengers_curr_customers: print " <tr>" print " <td><select name='%d:curr:flight'>" % i for flight in flights: print " <option>%s</option>" % flight print " </select></td>" print " <td><select name='%d:curr:customer'>" % i for customer in customers: print " <option value='%s'>%s %s %s %s</option>" % (customer[0], customer[1], customer[2], customer[3], customer[4]) print " </select></td>" print " </tr>" i += 1 if new_passengers_curr_customers > 0: print "</table>" return new_passengers_curr_customers Ok. So I think that was clear now. TIA, beno
-- http://mail.python.org/mailman/listinfo/python-list