Can't Add Variable

Victor Subervi victorsubervi at gmail.com
Mon Jan 4 18:28:13 CET 2010


Hi;
I have this code snippet:

    sql '''create table if not exists %sCustomerData (
      ID tinyint(8) unsigned primary key auto_increment,
      Email varchar(120) not null,
      PhoneNumber varchar(20) not null,
      BillingName varchar(80) not null,
      BillingAddress1 varchar(100) not null,
      BillingAddress2 varchar(100) null,
      BillingCity varchar(50) not null,
      BillingState varchar(2) not null,
      BillingPostalCode varchar(8) not null,
      ShippingName varchar(80) not null,
      ShippingAddress1 varchar(100) not null,
      ShippingAddress2 varchar(100) null,
      ShippingCity varchar(50) not null,
      ShippingState varchar(2) not null,
      ShippingPostalCode varchar(8) not null,
      TypeOfCard set("VISA", "MasterCard", "AmEx", "Discover", "PayPal")
null,
      CreditCardNumber tinyint(8) unsigned null,
      CreditCardExpMonth tinyint(2) unsigned null,
      CreditCardExpYear tinyint(4) unsigned null
      );''' % store

It throws this error:

[Mon Jan 04 09:23:54 2010] [error] [client 66.82.9.61]   File
"/var/www/html/angrynates.com/cart/cart2.py", line 62, referer:
http://angrynates.com/cart/cart.py
[Mon Jan 04 09:23:54 2010] [error] [client 66.82.9.61]     );''' % store,
referer: http://angrynates.com/cart/cart.py
[Mon Jan 04 09:23:54 2010] [error] [client 66.82.9.61]         ^, referer:
http://angrynates.com/cart/cart.py
[Mon Jan 04 09:23:54 2010] [error] [client 66.82.9.61] SyntaxError: invalid
syntax, referer: http://angrynates.com/cart/cart.py
[Mon Jan 04 09:23:54 2010] [error] [client 66.82.9.61] Premature end of
script headers: cart2.py, referer: http://angrynates.com/cart/cart.py

Variable "store" is defined. How is my syntax invalid? Total code follows.
TIA,
beno

#! /usr/bin/python

import string
import cgitb; cgitb.enable()
import MySQLdb
import cgi
import sys,os
sys.path.append(os.getcwd())
from login import login
import datetime, Cookie, random
from particulars import title, myCookie, ourOptions, whereToShip,
paymentOptionsPickup, paymentOptionsFax, paymentGateways, VISA, masterCard,
amEx, discover, payPal
from templateFrame import top, bottom
import time
import fpformat
from sets import Set

ourURL = string.split(__file__, 'html/')
ourURL = string.split(ourFile[1], '/')[0]

def commitSale():
  user, passwd, db, host = login()
  database = MySQLdb.connect(host, user, passwd, db)
  cursor= database.cursor()
  ourEmail = email()
  form = cgi.FieldStorage()
  which = form.getfirst('which')
  store = form.getfirst('store')
  patientID = form.getfirst('patientID')
  customerLoginEmail = form.getfirst('customerEmail') # This is for
customers who lost their login info
  customerLoginFirstName = form.getfirst('customerLoginFirstName')
  customerLoginLastName = form.getfirst('customerLoginLastName')
  customerLoginData = [patientID, customerLoginEmail,
customerLoginFirstName, customerLoginLastName]
  if (store == 'prescriptions') and ((customerLoginEmail is not None) or
(customerLoginFirstName is not None)):
    myMail(which, store, '', ourURL, '', '', customerLoginData)
  elif which == 'order':
    form = cgi.FieldStorage()
    tmpTable = form.getfirst('tmpTable')
    howPay = form.getfirst('howPay')
    ccNumber = form.getfirst('creditCardNumber')
    ccFirstHalf = ccNumber[0:8]
    ccSecondHalf = ccNumber[8:]
    sql '''create table if not exists %sCustomerData (
      ID tinyint(8) unsigned primary key auto_increment,
      Email varchar(120) not null,
      PhoneNumber varchar(20) not null,
      BillingName varchar(80) not null,
      BillingAddress1 varchar(100) not null,
      BillingAddress2 varchar(100) null,
      BillingCity varchar(50) not null,
      BillingState varchar(2) not null,
      BillingPostalCode varchar(8) not null,
      ShippingName varchar(80) not null,
      ShippingAddress1 varchar(100) not null,
      ShippingAddress2 varchar(100) null,
      ShippingCity varchar(50) not null,
      ShippingState varchar(2) not null,
      ShippingPostalCode varchar(8) not null,
      TypeOfCard set("VISA", "MasterCard", "AmEx", "Discover", "PayPal")
null,
      CreditCardNumber tinyint(8) unsigned null,
      CreditCardExpMonth tinyint(2) unsigned null,
      CreditCardExpYear tinyint(4) unsigned null
      );''' % store
    print sql
#    cursor.execute(sql)
    sql = '''insert into %sCustomerData (Email, PhoneNumber, BillingName,
BillingAddress1, BillingAddress2,
BillingCity, BillingState, BillingPostalCode, ShippingName,
ShippingAddress1, ShippingAddress2, ShippingCity,
ShippingState, ShippingPostalCode, TypeOfCard, CreditCardNumber,
CreditCardExpMonth, CreditCardExpYear)
value ("%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s",
"%s", "%s", "%s", "%s", "%s", "%s", "%s");'
% (store, form.getfirst('customerEmail'),
form.getfirst('customerPhoneNumber'), form.getfirst('customerBillingName'),
form.getfirst('customerBillingAddr1'),
form.getfirst('customerBillingAddr2'), form.getfirst('customerBillingCity'),
form.getfirst('customerBillingState'),
form.getfirst('customerBillingPostalCode'),
form.getfirst('customerShippingName'),
form.getfirst('shippingSameAsShipping'),
form.getfirst('customerShippingAddr1'),
form.getfirst('customerShippingAddr2'),
form.getfirst('customerShippingCity'),
form.getfirst('customerShippingState'),
form.getfirst('customerShippingPostalCode'),
form.getfirst('typeOfCard'), ccFirstHalf, form.getfirst('creditCartCVC'))
    print sql
#    cursor.execute(sql)
    db.commit()
    ccFirstHalf = None
    cursor.execute('select max(ID) from %sCustomerData;' % store)
    custID = cursor.fetchone()[0]
    myMail(which, store, BillingName, ourURL, tmpTable, ccSecondHalf)
    cursor.execute('describe %s;' % tmpTable)
    fields = [itm[0] for itm in cursor]
    cursor.execute('select * from %s;' % tmpTable)
    order = cursor.fetchall()
    allValues = []
    for item in order:
      itemValues = []
      i = 0
      while i < len(fields):
        itemValues(item[i])
        i += 1
      allValues.append(itemValues)
    order = ''
    for itemValues in allValues:
      i = 0
      for item in itemValues:
        order += '%s: %s\t' % (fields[i], item)
        i += 1
      order += '\n'
    order += 'Total: %s\n' % form.getfirst('total')

def cart2():
  user, passwd, db, host = login()
  db = MySQLdb.connect(host, user, passwd, db)
  cursor= db.cursor()
  print '''Content-Type: text/html\r\n
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
'''
  head = ''
  form = cgi.FieldStorage()
  numberOfProducts = int(form.getfirst('numberOfProducts'))
  total = form.getfirst('total')
  store = form.getfirst('store')
  i = 0
  html = ''
  deleteThese = []
  editThis = 0
  quantity = 0
  tmpTable = form.getfirst('tmpTable')
  while i < numberOfProducts:
    id = int(form.getfirst('id%d' % i))
    if form.getfirst('delete%d' % i) is not None:
      deleteThese.append(form.getfirst('delete%d' % i))
    if form.getfirst('edit%d' % i) is not None:
      editThis = int(form.getfirst('edit%d' % i))
      quantity = form.getfirst('quantity%d' % i)
      id = form.getfirst('quantityID%d' % i)
    i += 1
  i = 0
  while i < len(deleteThese):
    sql = 'delete from %s where ProdID=%s;' % (tmpTable, deleteThese[i])
    html += sql
    cursor.execute(sql)
    head = "<meta http-equiv='refresh' content='0;url=cart.py?store=%s' />"
% store
    i += 1
  if editThis != 0:
    sql = 'update %s set Quantity=%s where ProdID=%s;' % (tmpTable,
quantity, id)
    html += sql
    cursor.execute(sql)
    head = "<meta http-equiv='refresh'
content='0;url=cart.py?store=%s&quantity=%s' />" % (store, quantity)
  if head == '':
    paymentMethods = []
    cardTypes = []
    for paymentStore, paymentType in paymentOptionsPickup().iteritems():
      if (paymentStore == store) and (paymentType == 'on'):
        paymentMethods.append('pickup')
    for paymentStore, paymentType in paymentOptionsFax().iteritems():
      if (paymentStore == store) and (paymentType == 'on'):
        paymentMethods.append('fax')
    for cardStore, cardType in VISA().iteritems():
      if (cardStore == store) and (cardType == 'on'):
        cardTypes.append('VISA')
    for cardStore, cardType in masterCard().iteritems():
      if (cardStore == store) and (cardType == 'on'):
        cardTypes.append('MasterCard')
    for cardStore, cardType in amEx().iteritems():
      if (cardStore == store) and (cardType == 'on'):
        cardTypes.append('American Express')
    for cardStore, cardType in discover().iteritems():
      if (cardStore == store) and (cardType == 'on'):
        cardTypes.append('Discover')
    for cardStore, cardType in payPal().iteritems():
      if (cardStore == store) and (cardType == 'on'):
        cardTypes.append('PayPal')
    print '</head>'
    print "<input type='hidden' name='store' value='%s' />" % store
    print "<input type='hidden' name='total' value='%s' />" % total
    print "<input type='hidden' name='which' value='order' />"
    print "<input type='hidden' name='tmpTable' value='%s' />" % tmpTable
    print '''
<form action='simplemail/mail.py' method='post'>
<table>
  <tr>
'''
    if store != 'prescriptions':
      print '''
    <td colspan='2' align='center'><b>Billing Information</b></td>
  </tr><tr>
    <td><b>Name:</b></td>
    <td><input type='text' name='customerBillingName' size='20'
maxlength='60' /></td>
  </tr><tr>
    <td><b>Address 1:</b></td>
    <td><input type='text' name='customerBillingAddr1' size='40'
maxlength='80' /></td>
  </tr><tr>
    <td><b>Address 2:</b></td>
    <td><input type='text' name='customerBillingAddr2' size='40'
maxlength='80' /></td>
  </tr><tr>
    <td><b>City:</b></td>
    <td><input type='text' name='customerBillingCity' size='20'
maxlength='40' /></td>
  </tr><tr>
    <td><b>State:</b></td>
    <td><select name='customerBillingState'>
'''
    statesProducts, statesSpecialty = whereToShip()
    if store == 'products':
      whichStates = statesProducts
    else:
      whichStates = statesSpecialty
    for state in whichStates:
      print '<option>%s</option>' % state
    print '''
</select>
  </tr><tr>
    <td><b>Postal Code</b></td>
    <td><input type='text' name='customerBillingPostalCode' size='5'
maxlength='10' />
  </tr><tr>
    <td><b>Email Address</b></td>
    <td><input type='text' name='customerEmail' size='20' maxlength='50' />
  </tr><tr>
    <td><b>Phone Number</b></td>
    <td><input type='text' name='customerPhoneNumber' size='13'
maxlength='20' />
  </tr><tr>
    <td><b>Shipping Information</b></td>
    <td><i>Same as billing information?</i> <input type='checkbox'
name='shippingSameAsShipping' /></td>
  </tr><tr>
    <td colspan='2' align='center'><b>Shipping Information</b></td>
  </tr><tr>
    <td><b>Name:</b></td>
    <td><input type='text' name='customerShippingName' size='20'
maxlength='60' /></td>
  </tr><tr>
    <td><b>Address 1:</b></td>
    <td><input type='text' name='customerShippingAddr1' size='40'
maxlength='80' /></td>
  </tr><tr>
    <td><b>Address 2:</b></td>
    <td><input type='text' name='customerShippingAddr2' size='40'
maxlength='80' /></td>
  </tr><tr>
    <td><b>City:</b></td>
    <td><input type='text' name='customerShippingCity' size='20'
maxlength='40' /></td>
  </tr><tr>
    <td><b>State:</b></td>
    <td><select name='customerShippingState'>
'''
      statesProducts, statesSpecialty = whereToShip()
      if store == 'products':
        whichStates = statesProducts
      else:
        whichStates = statesSpecialty
      for state in whichStates:
        print '<option>%s</option>' % state
      print '''
</select>
  </tr><tr>
    <td><b>Postal Code</b></td>
    <td><input type='text' name='customerShippingPostalCode' size='5'
maxlength='10' />
  </tr><tr>
    <td colspan='2' align='center'><b>Credit Card Information</b></td>
  </tr><tr>
    <td><b>Type of Card:</b></td>
    <td><select name='typeOfCard'>
'''
      for card in cardTypes:
        print '<option>%s</option>' % card
      print '''
</select></td>
  </tr><tr>
    <td><b>Credit Card Number:</b></td>
    <td><input type='text' name='creditCardNumber' size='16' maxlength='24'
/></td>
  </tr><tr>
    <td><b>CVC Code:</b></td>
    <td><input type='text' name='creditCartCVC' size='3' maxlength='8'
/></td>
  </tr><tr>
    <td><b>Expiration Date:</b></td>
    <td>Month: <select name='creditCardExpMonth'>
'''
      i = 0
      while i < 12:
        i += 1
        print '<option>%d</option>' % i
      print "</select> Year: <select name='creditCardExpYear'>"
      theYear = int(datetime.datetime.now().strftime('%Y'))
      i = 0
      while i < 10:
        print '<option>%d</option>' % (theYear + i)
        i += 1
      print '''
</select></td>
  </tr><tr>
    <td colspan='2' align='center'><b>Method of Payment</b></td>
  </tr><tr>
    <td colspan='2'><b>Pay by Credit Card:</b>
 <input type='radio' name='howPay' checked='yes' value='cc' />
'''
      for method in paymentMethods:
        print "&#xa0;&#xa0;&#xa0;<b>Pay by %s:</b> <input type='radio'
name='howPay' value='%s' />" % (method[0].upper() + method[1:], method)
      print '''
  </tr><tr>
    <td colspan='2' align='center'><input type='submit' value=' Send '
/></td>
'''
    else:
      patientID = form.getfirst('patientID')
      sql = 'select FirstName, LastName from patientsPersonalData where
ID=%s;' % patientID
      cursor.execute(sql)
      print "%s, please tell us how you would like to pay for this order?" %
(cursor.fetchone()[0] + ' ' + cursor.fetchone()[1])
PRINT PAYMENT OPTION STUFF HERE
      print "If you would like to pay by credit card, please fill in the
following:"
      print '''
PRINT CC INFO HERE
  </tr>
</table>
</form>
</body>
</html>
'''
    commitSale()
  else:
    print head
    print '</head>'
    print '<body>'
#    print html
    print '</html>'

cart2()

-- 
The Logos has come to bear
http://logos.13gems.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100104/129125e7/attachment.html>


More information about the Python-list mailing list