Im writing this to kind of share my ideas and also welcome yours in this matter.
count me as a fresher here
import MySQLdb,time
#creating a separator
separator = "--------------------------------------------------------------------"
#connection defination
db= MySQLdb.connect(host="localhost", user="root", passwd="rooter",
db="test")
print separator
#warning
print ("&&&&&&&&&&&&&&&&&&&&&&&&&& date format yyyymmdd.&&&&&&&&&&&&&&&&&&&")
print separator
#Guest salutations
print "++++ Hello, welcome to Project manager by pytbyte pythons+++"
now = time.ctime()
print "it's now: ", now
print separator
print separator
#getting values from user
Guest = raw_input("Guest: ")
Project = raw_input("Project: ")
Partners = raw_input("Partners: ")
Goals = raw_input("Goals: ")
Budget = raw_input("Budget: ")
Begindate = int( raw_input("Date of begin: ") )
print separator
#allowing youser to view data being inserted
print "Guest: [" + Guest + "]"
print "Project: [" + Project + "]"
print "Partners: [" + Partners + "]"
print "Goals: [" + Goals + "]"
print "Budget: [" + Budget + "]"
print "Begindate: "+ str(Begindate)
print separator
#invoking cursor
cursor = db.cursor()
#preparing data to be inserted to database
stmt = "INSERT INTO trial (Guest, Project, Partners, Goals, Budget, Begindate) VALUES ('"
stmt = stmt + Guest
stmt = stmt + "', '"
stmt = stmt + Project
stmt = stmt + "', '"
stmt = stmt + Partners
stmt = stmt + "', '"
stmt = stmt + Goals
stmt = stmt + "', '"
stmt = stmt + Budget
stmt = stmt + "', "
stmt = stmt + str(Begindate)
stmt = stmt + ")"
#cursor performs the insertion
cursor.execute(stmt)
print (" Your project has been submited!")
print " +++++++++ Goodbye,it's been nice working for you+++++++++"
print separator
print now
#stopping acctivities and closing database
cursor.close ()
db.commit ()
now another one
import MySQLdb
db= MySQLdb.connect(host="localhost", user="root", passwd="rooter",
db="testdb")
try:
title = raw_input("Please enter a book title: ")
if title == "" :
exit
author = raw_input("Please enter the author's name: ")
pubdate = int( raw_input("Enter the publication year: ") )
except:
print "Invalid value"
exit
print "Title: [" + title + "]"
print "Author: ["+ author + "]"
print "Publication Date: " + str(pubdate)
cursor = db.cursor()
stmt = "INSERT INTO Books (BookName, BookAuthor, PublicationDate) VALUES ('"
stmt = stmt + title
stmt = stmt + "', '"
stmt = stmt + author
stmt = stmt + "', "
stmt = stmt + str(pubdate)
stmt = stmt + ")"
cursor.execute(stmt)
print "Record added!"
cursor.close ()
db.commit ()