Sunday, May 15, 2016

Python CGI Database (4 of 4)

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sqlite3
import cgi

print "Content-Type: application/xhtml+xml; charset=utf-8\n"

print '<!DOCTYPE html>'
print '<html xmlns="http://www.w3.org/1999/xhtml" lang="fr">'
print '<head>'
print '    <title>eCarnet - Employées d un service</title>'
print '</head>'
print '<body>'

form = cgi.FieldStorage()
id_service = str(form["matricule"].value)
nom = str(form["nom"].value)
prenom = str(form["prenom"].value)
matricule = str(form["matricule"].value)
tel_fixe = str(form["tel_fixe"].value)

db_connection = sqlite3.connect('database.test-01.db')
db_connection.row_factory = sqlite3.Row
cursor = db_connection.cursor()
cursor.execute("INSERT INTO employe(matricule, prenom, nom, tel_fixe, id_service) VALUES (?, ?, ?, ?, ?)", (matricule, prenom, nom, tel_fixe, id_service))
db_connection.commit()
db_connection.close()

print '    <h1>Ajout de l employé - ' + prenom + ' ' + nom + ' -</h1>'
print '    <p>' + prenom + ' ' + nom + ' a bien été ajouté dans la base de données</p>'
print '    <p><a href="eCarnet_home.py">Retour au eCarnet.</a></p>'
print ' </body>'
print ' </html>'

No comments:

Post a Comment