Hi;<br>I have this code snippet:<br><br> sql '''create table if not exists %sCustomerData (<br> ID tinyint(8) unsigned primary key auto_increment,<br> Email varchar(120) not null,<br> PhoneNumber varchar(20) not null,<br>
BillingName varchar(80) not null,<br> BillingAddress1 varchar(100) not null,<br> BillingAddress2 varchar(100) null,<br> BillingCity varchar(50) not null,<br> BillingState varchar(2) not null,<br>
BillingPostalCode varchar(8) not null,<br> ShippingName varchar(80) not null,<br> ShippingAddress1 varchar(100) not null,<br> ShippingAddress2 varchar(100) null,<br> ShippingCity varchar(50) not null,<br>
ShippingState varchar(2) not null,<br> ShippingPostalCode varchar(8) not null,<br> TypeOfCard set("VISA", "MasterCard", "AmEx", "Discover", "PayPal") null,<br>
CreditCardNumber tinyint(8) unsigned null,<br> CreditCardExpMonth tinyint(2) unsigned null,<br> CreditCardExpYear tinyint(4) unsigned null<br> );''' % store<br><br>It throws this error:<br>
<br>[Mon Jan 04 09:23:54 2010] [error] [client 66.82.9.61] File "/var/www/html/<a href="http://angrynates.com/cart/cart2.py">angrynates.com/cart/cart2.py</a>", line 62, referer: <a href="http://angrynates.com/cart/cart.py">http://angrynates.com/cart/cart.py</a><br>
[Mon Jan 04 09:23:54 2010] [error] [client 66.82.9.61] );''' % store, referer: <a href="http://angrynates.com/cart/cart.py">http://angrynates.com/cart/cart.py</a><br>[Mon Jan 04 09:23:54 2010] [error] [client 66.82.9.61] ^, referer: <a href="http://angrynates.com/cart/cart.py">http://angrynates.com/cart/cart.py</a><br>
[Mon Jan 04 09:23:54 2010] [error] [client 66.82.9.61] SyntaxError: invalid syntax, referer: <a href="http://angrynates.com/cart/cart.py">http://angrynates.com/cart/cart.py</a><br>[Mon Jan 04 09:23:54 2010] [error] [client 66.82.9.61] Premature end of script headers: cart2.py, referer: <a href="http://angrynates.com/cart/cart.py">http://angrynates.com/cart/cart.py</a><br>
<br clear="all">Variable "store" is defined. How is my syntax invalid? Total code follows.<br>TIA,<br>beno<br><br>#! /usr/bin/python<br><br>import string<br>import cgitb; cgitb.enable()<br>import MySQLdb<br>import cgi<br>
import sys,os<br>sys.path.append(os.getcwd())<br>from login import login<br>import datetime, Cookie, random<br>from particulars import title, myCookie, ourOptions, whereToShip, paymentOptionsPickup, paymentOptionsFax, paymentGateways, VISA, masterCard, amEx, discover, payPal<br>
from templateFrame import top, bottom<br>import time<br>import fpformat<br>from sets import Set<br><br>ourURL = string.split(__file__, 'html/')<br>ourURL = string.split(ourFile[1], '/')[0]<br><br>def commitSale():<br>
user, passwd, db, host = login()<br> database = MySQLdb.connect(host, user, passwd, db)<br> cursor= database.cursor()<br> ourEmail = email()<br> form = cgi.FieldStorage()<br> which = form.getfirst('which')<br>
store = form.getfirst('store')<br> patientID = form.getfirst('patientID')<br> customerLoginEmail = form.getfirst('customerEmail') # This is for customers who lost their login info<br> customerLoginFirstName = form.getfirst('customerLoginFirstName')<br>
customerLoginLastName = form.getfirst('customerLoginLastName')<br> customerLoginData = [patientID, customerLoginEmail, customerLoginFirstName, customerLoginLastName]<br> if (store == 'prescriptions') and ((customerLoginEmail is not None) or (customerLoginFirstName is not None)):<br>
myMail(which, store, '', ourURL, '', '', customerLoginData)<br> elif which == 'order':<br> form = cgi.FieldStorage()<br> tmpTable = form.getfirst('tmpTable')<br> howPay = form.getfirst('howPay')<br>
ccNumber = form.getfirst('creditCardNumber')<br> ccFirstHalf = ccNumber[0:8]<br> ccSecondHalf = ccNumber[8:]<br> sql '''create table if not exists %sCustomerData (<br> ID tinyint(8) unsigned primary key auto_increment,<br>
Email varchar(120) not null,<br> PhoneNumber varchar(20) not null,<br> BillingName varchar(80) not null,<br> BillingAddress1 varchar(100) not null,<br> BillingAddress2 varchar(100) null,<br> BillingCity varchar(50) not null,<br>
BillingState varchar(2) not null,<br> BillingPostalCode varchar(8) not null,<br> ShippingName varchar(80) not null,<br> ShippingAddress1 varchar(100) not null,<br> ShippingAddress2 varchar(100) null,<br>
ShippingCity varchar(50) not null,<br> ShippingState varchar(2) not null,<br> ShippingPostalCode varchar(8) not null,<br> TypeOfCard set("VISA", "MasterCard", "AmEx", "Discover", "PayPal") null,<br>
CreditCardNumber tinyint(8) unsigned null,<br> CreditCardExpMonth tinyint(2) unsigned null,<br> CreditCardExpYear tinyint(4) unsigned null<br> );''' % store<br> print sql<br># cursor.execute(sql)<br>
sql = '''insert into %sCustomerData (Email, PhoneNumber, BillingName, BillingAddress1, BillingAddress2,<br>BillingCity, BillingState, BillingPostalCode, ShippingName, ShippingAddress1, ShippingAddress2, ShippingCity,<br>
ShippingState, ShippingPostalCode, TypeOfCard, CreditCardNumber, CreditCardExpMonth, CreditCardExpYear)<br>value ("%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s");'<br>
% (store, form.getfirst('customerEmail'), form.getfirst('customerPhoneNumber'), form.getfirst('customerBillingName'),<br>form.getfirst('customerBillingAddr1'), form.getfirst('customerBillingAddr2'), form.getfirst('customerBillingCity'),<br>
form.getfirst('customerBillingState'), form.getfirst('customerBillingPostalCode'), form.getfirst('customerShippingName'),<br>form.getfirst('shippingSameAsShipping'), form.getfirst('customerShippingAddr1'), form.getfirst('customerShippingAddr2'),<br>
form.getfirst('customerShippingCity'), form.getfirst('customerShippingState'), form.getfirst('customerShippingPostalCode'),<br>form.getfirst('typeOfCard'), ccFirstHalf, form.getfirst('creditCartCVC'))<br>
print sql<br># cursor.execute(sql)<br> db.commit()<br> ccFirstHalf = None<br> cursor.execute('select max(ID) from %sCustomerData;' % store)<br> custID = cursor.fetchone()[0]<br> myMail(which, store, BillingName, ourURL, tmpTable, ccSecondHalf)<br>
cursor.execute('describe %s;' % tmpTable)<br> fields = [itm[0] for itm in cursor]<br> cursor.execute('select * from %s;' % tmpTable)<br> order = cursor.fetchall()<br> allValues = []<br> for item in order:<br>
itemValues = []<br> i = 0<br> while i < len(fields):<br> itemValues(item[i])<br> i += 1<br> allValues.append(itemValues)<br> order = ''<br> for itemValues in allValues:<br>
i = 0<br> for item in itemValues:<br> order += '%s: %s\t' % (fields[i], item)<br> i += 1<br> order += '\n'<br> order += 'Total: %s\n' % form.getfirst('total')<br>
<br>def cart2():<br> user, passwd, db, host = login()<br> db = MySQLdb.connect(host, user, passwd, db)<br> cursor= db.cursor()<br> print '''Content-Type: text/html\r\n<br><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><br>
<html><br><head><br>'''<br> head = ''<br> form = cgi.FieldStorage()<br> numberOfProducts = int(form.getfirst('numberOfProducts'))<br> total = form.getfirst('total')<br> store = form.getfirst('store')<br>
i = 0<br> html = ''<br> deleteThese = []<br> editThis = 0<br> quantity = 0<br> tmpTable = form.getfirst('tmpTable')<br> while i < numberOfProducts:<br> id = int(form.getfirst('id%d' % i))<br>
if form.getfirst('delete%d' % i) is not None:<br> deleteThese.append(form.getfirst('delete%d' % i))<br> if form.getfirst('edit%d' % i) is not None:<br> editThis = int(form.getfirst('edit%d' % i))<br>
quantity = form.getfirst('quantity%d' % i)<br> id = form.getfirst('quantityID%d' % i)<br> i += 1<br> i = 0<br> while i < len(deleteThese):<br> sql = 'delete from %s where ProdID=%s;' % (tmpTable, deleteThese[i])<br>
html += sql<br> cursor.execute(sql)<br> head = "<meta http-equiv='refresh' content='0;url=cart.py?store=%s' />" % store<br> i += 1<br> if editThis != 0:<br> sql = 'update %s set Quantity=%s where ProdID=%s;' % (tmpTable, quantity, id)<br>
html += sql<br> cursor.execute(sql)<br> head = "<meta http-equiv='refresh' content='0;url=cart.py?store=%s&quantity=%s' />" % (store, quantity)<br> if head == '':<br>
paymentMethods = []<br> cardTypes = []<br> for paymentStore, paymentType in paymentOptionsPickup().iteritems():<br> if (paymentStore == store) and (paymentType == 'on'):<br> paymentMethods.append('pickup')<br>
for paymentStore, paymentType in paymentOptionsFax().iteritems():<br> if (paymentStore == store) and (paymentType == 'on'):<br> paymentMethods.append('fax')<br> for cardStore, cardType in VISA().iteritems():<br>
if (cardStore == store) and (cardType == 'on'):<br> cardTypes.append('VISA')<br> for cardStore, cardType in masterCard().iteritems():<br> if (cardStore == store) and (cardType == 'on'):<br>
cardTypes.append('MasterCard')<br> for cardStore, cardType in amEx().iteritems():<br> if (cardStore == store) and (cardType == 'on'):<br> cardTypes.append('American Express')<br>
for cardStore, cardType in discover().iteritems():<br> if (cardStore == store) and (cardType == 'on'):<br> cardTypes.append('Discover')<br> for cardStore, cardType in payPal().iteritems():<br>
if (cardStore == store) and (cardType == 'on'):<br> cardTypes.append('PayPal')<br> print '</head>'<br> print "<input type='hidden' name='store' value='%s' />" % store<br>
print "<input type='hidden' name='total' value='%s' />" % total<br> print "<input type='hidden' name='which' value='order' />"<br> print "<input type='hidden' name='tmpTable' value='%s' />" % tmpTable<br>
print '''<br><form action='simplemail/mail.py' method='post'><br><table><br> <tr><br>'''<br> if store != 'prescriptions':<br> print '''<br>
<td colspan='2' align='center'><b>Billing Information</b></td><br> </tr><tr><br> <td><b>Name:</b></td><br> <td><input type='text' name='customerBillingName' size='20' maxlength='60' /></td><br>
</tr><tr><br> <td><b>Address 1:</b></td><br> <td><input type='text' name='customerBillingAddr1' size='40' maxlength='80' /></td><br>
</tr><tr><br> <td><b>Address 2:</b></td><br> <td><input type='text' name='customerBillingAddr2' size='40' maxlength='80' /></td><br>
</tr><tr><br> <td><b>City:</b></td><br> <td><input type='text' name='customerBillingCity' size='20' maxlength='40' /></td><br> </tr><tr><br>
<td><b>State:</b></td><br> <td><select name='customerBillingState'><br>'''<br> statesProducts, statesSpecialty = whereToShip()<br> if store == 'products':<br>
whichStates = statesProducts<br> else:<br> whichStates = statesSpecialty<br> for state in whichStates:<br> print '<option>%s</option>' % state<br> print '''<br></select><br>
</tr><tr><br> <td><b>Postal Code</b></td><br> <td><input type='text' name='customerBillingPostalCode' size='5' maxlength='10' /><br> </tr><tr><br>
<td><b>Email Address</b></td><br> <td><input type='text' name='customerEmail' size='20' maxlength='50' /><br> </tr><tr><br> <td><b>Phone Number</b></td><br>
<td><input type='text' name='customerPhoneNumber' size='13' maxlength='20' /><br> </tr><tr><br> <td><b>Shipping Information</b></td><br>
<td><i>Same as billing information?</i> <input type='checkbox' name='shippingSameAsShipping' /></td><br> </tr><tr><br> <td colspan='2' align='center'><b>Shipping Information</b></td><br>
</tr><tr><br> <td><b>Name:</b></td><br> <td><input type='text' name='customerShippingName' size='20' maxlength='60' /></td><br>
</tr><tr><br> <td><b>Address 1:</b></td><br> <td><input type='text' name='customerShippingAddr1' size='40' maxlength='80' /></td><br>
</tr><tr><br> <td><b>Address 2:</b></td><br> <td><input type='text' name='customerShippingAddr2' size='40' maxlength='80' /></td><br>
</tr><tr><br> <td><b>City:</b></td><br> <td><input type='text' name='customerShippingCity' size='20' maxlength='40' /></td><br>
</tr><tr><br> <td><b>State:</b></td><br> <td><select name='customerShippingState'><br>'''<br> statesProducts, statesSpecialty = whereToShip()<br>
if store == 'products':<br> whichStates = statesProducts<br> else:<br> whichStates = statesSpecialty<br> for state in whichStates:<br> print '<option>%s</option>' % state<br>
print '''<br></select><br> </tr><tr><br> <td><b>Postal Code</b></td><br> <td><input type='text' name='customerShippingPostalCode' size='5' maxlength='10' /><br>
</tr><tr><br> <td colspan='2' align='center'><b>Credit Card Information</b></td><br> </tr><tr><br> <td><b>Type of Card:</b></td><br>
<td><select name='typeOfCard'><br>'''<br> for card in cardTypes:<br> print '<option>%s</option>' % card<br> print '''<br></select></td><br>
</tr><tr><br> <td><b>Credit Card Number:</b></td><br> <td><input type='text' name='creditCardNumber' size='16' maxlength='24' /></td><br>
</tr><tr><br> <td><b>CVC Code:</b></td><br> <td><input type='text' name='creditCartCVC' size='3' maxlength='8' /></td><br> </tr><tr><br>
<td><b>Expiration Date:</b></td><br> <td>Month: <select name='creditCardExpMonth'><br>'''<br> i = 0<br> while i < 12:<br> i += 1<br> print '<option>%d</option>' % i<br>
print "</select> Year: <select name='creditCardExpYear'>"<br> theYear = int(datetime.datetime.now().strftime('%Y'))<br> i = 0<br> while i < 10:<br> print '<option>%d</option>' % (theYear + i)<br>
i += 1<br> print '''<br></select></td><br> </tr><tr><br> <td colspan='2' align='center'><b>Method of Payment</b></td><br> </tr><tr><br>
<td colspan='2'><b>Pay by Credit Card:</b><br> <input type='radio' name='howPay' checked='yes' value='cc' /><br>'''<br> for method in paymentMethods:<br>
print "   <b>Pay by %s:</b> <input type='radio' name='howPay' value='%s' />" % (method[0].upper() + method[1:], method)<br> print '''<br>
</tr><tr><br> <td colspan='2' align='center'><input type='submit' value=' Send ' /></td><br>'''<br> else:<br> patientID = form.getfirst('patientID')<br>
sql = 'select FirstName, LastName from patientsPersonalData where ID=%s;' % patientID<br> cursor.execute(sql)<br> print "%s, please tell us how you would like to pay for this order?" % (cursor.fetchone()[0] + ' ' + cursor.fetchone()[1])<br>
PRINT PAYMENT OPTION STUFF HERE<br> print "If you would like to pay by credit card, please fill in the following:"<br> print '''<br>PRINT CC INFO HERE<br> </tr><br></table><br>
</form><br></body><br></html><br>'''<br> commitSale()<br> else:<br> print head<br> print '</head>'<br> print '<body>'<br># print html<br> print '</html>'<br>
<br>cart2()<br><br>-- <br>The Logos has come to bear<br><a href="http://logos.13gems.com/">http://logos.13gems.com/</a><br>