Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # Import modules for CGI handling
- import cgi, cgitb
- import sqlite3
- conn = sqlite3.connect('../databases/StudentForms.db')
- c = conn.cursor()
- # Create instance of FieldStorage
- form = cgi.FieldStorage()
- # Get data from fields
- first_name = form.getvalue("firstName")
- last_name = form.getvalue("lastName")
- courses = form.getvalue("courses")
- work_type = form.getvalue("worktype")
- grade = form.getvalue("grade")
- fullName = first_name + ' ' + last_name
- # Insert user 1
- c.execute ('INSERT INTO Work(WorkType, Grade) VALUES(?,?)', (work_type , grade))
- workTypeID = c.lastrowid
- c.execute ('INSERT INTO Course(Name) VALUES(?)', [courses])
- courseID = c.lastrowid
- c.execute ('INSERT INTO Students(Name, Work_WorkID, Course_CourseID) VALUES(?, ?, ?)', (fullName, workTypeID, courseID))
- # Save (commit) the changes
- conn.commit()
- print "Content-type:text/html\r\n\r\n"%>
- <html>
- <head>
- <title>Student Database</title>
- <link rel='Stylesheet' href='css/style.css'>
- </head>
- <body><%
- print "<h1>Student Database</h1>"
- c.execute("SELECT * FROM Students")
- rows = c.fetchall()
- for row in rows:
- print row[1]
- CourseID = row[2]
- WorkID = row[3]
- studentName = row[1]
- c.execute("select Name FROM Course where CourseID = " + str(CourseID))
- courseName = c.fetchall()
- print "%s" % (courseName[0])
- c.execute("select * FROM Work where WorkID = " + str(WorkID))
- Graderow = c.fetchone()
- int(xGrade) = Graderow[2]
- nGrade = lettGrade(xGrade)
- print str(Graderow[1]) + " , " + str(Graderow[2])
- print nGrade
- print "</br>"
- print "<body>"%>
- </br> <%
- print "<a href='HTML Form.html'> <input type='Submit' value='Add Another Student' name='submitBtn'> </a>"
- # We can also close the connection if we are done with it.
- # Just be sure any changes have been committed or they will be lost.
- conn.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement