Advertisement
Guest User

Untitled

a guest
Dec 5th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python
  2. # Import modules for CGI handling
  3.  
  4. import cgi, cgitb
  5. import sqlite3
  6. conn = sqlite3.connect('../databases/StudentForms.db')
  7. c = conn.cursor()
  8.  
  9. # Create instance of FieldStorage
  10. form = cgi.FieldStorage()
  11.  
  12. # Get data from fields
  13. first_name = form.getvalue("firstName")
  14. last_name = form.getvalue("lastName")
  15. courses = form.getvalue("courses")
  16. work_type = form.getvalue("worktype")
  17. grade = form.getvalue("grade")
  18.  
  19. fullName = first_name + ' ' + last_name
  20.  
  21. # Insert user 1
  22. c.execute ('INSERT INTO Work(WorkType, Grade) VALUES(?,?)', (work_type , grade))
  23. workTypeID = c.lastrowid
  24. c.execute ('INSERT INTO Course(Name) VALUES(?)', [courses])
  25. courseID = c.lastrowid
  26. c.execute ('INSERT INTO Students(Name, Work_WorkID, Course_CourseID) VALUES(?, ?, ?)', (fullName, workTypeID, courseID))
  27.  
  28. # Save (commit) the changes
  29. conn.commit()
  30.  
  31. print "Content-type:text/html\r\n\r\n"%>
  32. <html>
  33. <head>
  34. <title>Student Database</title>
  35. <link rel='Stylesheet' href='css/style.css'>
  36. </head>
  37. <body><%
  38. print "<h1>Student Database</h1>"
  39. c.execute("SELECT * FROM Students")
  40. rows = c.fetchall()
  41. for row in rows:
  42. print row[1]
  43. CourseID = row[2]
  44. WorkID = row[3]
  45. studentName = row[1]
  46. c.execute("select Name FROM Course where CourseID = " + str(CourseID))
  47. courseName = c.fetchall()
  48. print "%s" % (courseName[0])
  49.  
  50. c.execute("select * FROM Work where WorkID = " + str(WorkID))
  51. Graderow = c.fetchone()
  52. int(xGrade) = Graderow[2]
  53. nGrade = lettGrade(xGrade)
  54. print str(Graderow[1]) + " , " + str(Graderow[2])
  55. print nGrade
  56. print "</br>"
  57. print "<body>"%>
  58. </br> <%
  59. print "<a href='HTML Form.html'> <input type='Submit' value='Add Another Student' name='submitBtn'> </a>"
  60.  
  61. # We can also close the connection if we are done with it.
  62. # Just be sure any changes have been committed or they will be lost.
  63. conn.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement