post
poster: Thetawaves
description: form save code take 2
language: Python
[download]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
def save_org(fields):
    db = db_session()
    cursor = db.cursor
    keys = fields.keys()
    keys = map(MySQLdb.escape_string, keys)
    key_str = ",".join(keys)
    val_list = []
    for key in keys:
        val_list.append(fields[key][0])
    val_list = map(MySQLdb.escape_string, val_list)
    val_str = "'" + "','".join(val_list) + "'"
    query =  "INSERT INTO org_list (" + key_str + ") VALUES (" + val_str+ ")"
    cursor.execute(query)
    redirect('main_page')
    sys.exit(0)