Lab 3 part 2 filtering the application - JadenGil/Jaden-Tech-Journal GitHub Wiki

Edit the form in button.html and add the following code:

image

Then in app.py add the circled lines to the code:

image

Now when you enter a name and email on the website it will take you to this page:

image


Deliverable 1:

image

Deliverable 2:

image

The highlighted code shows how I made it so it'll only accept inputs from a calendar:

image

Deliverable 3:

The website successfully saved the Owner and pets name and birth. And it is tied to the owner ID:

image


Pets app.py code:

app = Flask(__name__)

db = pymysql.connect(host='192.168.1.10', user='webserver2', database='pets', password='mypass')

@app.route("/test_database", methods=["POST"])
def test_database():
  cursor = db.cursor()
  sql = "SELECT * FROM pets"
  cursor.execute(sql)
  results = cursor.fetchall()
  for item in results:
    print(item)
  return "ok"

@app.route("/form_submitted", methods=["POST"])
def form_submitted():
  owner_name = request.form['owner_name']
  cat_name = request.form['cat_name']
  cat_birth = request.form['cat_birth']

  cursor2 = db.cursor()
  sql = "INSERT INTO owner (name) VALUES (%s)"
  cursor2.execute(sql, (owner_name))
  db.commit()
  cursor2.close()
 
  cursor3 = db.cursor()
  sql = "INSERT INTO cats (name, birth) VALUES (%s, %s)"
  cursor3.execute(sql, (cat_name, cat_birth))
  db.commit()
  cursor3.close()
  return "Form Submitted"

@app.route("/", methods=["GET"])
def home():
  return render_template("pets.html", title="pets", name="Jaden")