Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathprocesscustomer.cgi
More file actions
Latest commit
executable file
·50 lines (42 loc) · 1.85 KB
/
Copy pathprocesscustomer.cgi
File metadata and controls
executable file
·50 lines (42 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/local/bin/python3
importcgi
frompizza_kitchen_helpersimport*
defprocess_form(form_data):
first_name=form_data.getvalue("first")
last_name=form_data.getvalue("last")
street=form_data.getvalue("street")
town=form_data.getvalue("town")
post_code=form_data.getvalue("postcode")
email=form_data.getvalue("email")
returnfirst_name, last_name, street, town, post_code, email
definsert_customer(db, cursor,first_name, last_name, street, town, post_code, email):
sql="""insert into customer
(first_name, last_name, street_address, town, post_code, email_address)
values ('{0}','{1}','{2}','{3}','{4}','{5}')
""".format(first_name, last_name, street, town, post_code, email)
cursor.execute(sql)
db.commit()
defselect_customer(db,cursor,first_name, last_name, post_code):
sql="""select customer_id
from customer
where first_name = '{0}' and last_name = '{1}' and post_code = '{2}'
""".format(first_name, last_name, post_code)
cursor.execute(sql)
customer_id=cursor.fetchall()
returncustomer_id[0][0]
if__name__=="__main__":
try:
html_top("New Customer Added")
form_data=cgi.FieldStorage()
first_name, last_name, street, town, post_code, email=process_form(form_data)
db,cursor=connect_pizza_database()
insert_customer(db, cursor,first_name, last_name, street, town, post_code, email)
customer_id=select_customer(db,cursor,first_name, last_name, post_code)
print("<h1>Pizza Kitchen</h1>")
print("<h2>Customer Confirmation</h2>")
print("<p>Thank you for registering with us. Your customer number is:</p>")
print("<p><h1>{0}</h1></p>".format(customer_id))
cursor.close()
html_tail()
except:
cgi.print_exception()