Exemple #1
0
def home():
    if 'email' in session:
        cursor.execute('select * from products')
        product_list = cursor.fetchall()
        try:
            return render_template('home.html', product_list=product_list)
        except TemplateNotFound:
            abort(404)
    else:
        try:
            return redirect(url_for('auth.index'))
        except TemplateNotFound:
            abort(404)
Exemple #2
0
def product_details(product_id, product_name):
    if request.method == 'POST':
        return
    else:
        if 'email' in session:
            cursor.execute('select * from products where id="' + product_id +
                           '" and product_name = "' + product_name + '"')
            product = cursor.fetchone()
            try:
                return render_template('product-details.html', product=product)
            except TemplateNotFound:
                abort(404)
        else:
            try:
                return redirect(url_for('auth.index'))
            except TemplateNotFound:
                abort(404)
Exemple #3
0
def shop():
    if request.method == 'POST':
        search_product = request.form['search']
        if search_product == "":
            try:
                return redirect(url_for('home.home'))
            except TemplateNotFound:
                abort(404)
        else:
            cursor.execute('select * from products where product_name = "' +
                           search_product + '" or brand = "' + search_product +
                           '" or category = "' + search_product +
                           '" order by product_name')
            search_res = cursor.fetchall()
            try:
                return render_template('shop.html', products=search_res)
            except TemplateNotFound:
                abort(404)
    else:
        if 'email' in session:
            email_session = session['email']
            cursor.execute('select * from products')
            product = cursor.fetchall()
            total = len(product)
            cursor.execute(
                'select pr.*, ca.email from products pr, cart ca where'
                ' pr.id = ca.product_id and ca.email = "' + email_session +
                '" and ca.sold = "0"')
            cart_item = cursor.fetchall()
            print(cart_item)
            try:
                return render_template('shop.html',
                                       products=product,
                                       total_product=total,
                                       cart_item=cart_item)
            except TemplateNotFound:
                abort(404)
        else:
            try:
                return redirect(url_for('auth.index'))
            except TemplateNotFound:
                abort(404)
Exemple #4
0
from db_conn import cursor, db

sql = "INSERT INTO `team_name`  SET `scores` = '40' , `email` = '*****@*****.**' "
try:
    # Execute the SQL command
    cursor.execute(sql)
    # Commit your changes in the database
    db.commit()
except Exception as e:
    print(e)
    # Rollback in
    db.rollback()

# disconnect from server
db.close()
Exemple #5
0
from db_conn import cursor, db

cursor.execute("SELECT `email`, `scores`,  `id`  FROM `team_name` ORDER BY id DESC ")
db_data = cursor.fetchall()
print(type(db_data))  # tuple type  data
print(db_data)
for row in db_data:
    print(type(row))  # dict type  data
    # print(row)
    # print('record  id===', int(row[0]), ' scores === ', row[1], ' email === ', row[2])
    print('record  id===', int(row['id']), ' scores === ', row['scores'], ' email === ', row['email'])
    # print(type(row['email'])) is similar to  print(type(row[2]))

# disconnect from server
db.close()