[Tutor] Searching for email id in MySQL giving wrong results
John Joseph
jjk_saji at yahoo.com
Sun Jan 29 08:49:54 CET 2006
Hi
I am sending the code of the function
"searchbyemail" and the output of the program when I
run
I am trying to search and display the results , even
if we give a part of the email_id
thanks
Joseph John
**************** SEARCH by email _id function
********************************
################################################################################
def searchbyemail():
s_email = raw_input("Enter the Email to be
searched ")
db = MySQLdb.connect(host="localhost",user =
"john", passwd = "asdlkj", db = 'learnpython')
entry = db.cursor()
entry.execute("""SELECT * FROM contact WHERE
email_id = %s """, (s_email,))
p = entry.fetchall()
print p
#######################################################################
*** Output of the short run *********
[john at john experiement]$ python mysqlentry.py
Data Base Entry for the Testing Env
0 - Quit
1 - Enter the Data
2 - Display The data
3 - Search The Company
4 - Delete Some info
Choice :........2
(('Joseph', 'joseph at asd.com', '1234', '4321'),
('John', 'john at qwe.com', '4567', '7654'), ('CityBank',
'bank at money.com', '987', '789'), ('ABN amro',
'loan at money.com', '456', '654'))
Data Base Entry for the Testing Env
0 - Quit
1 - Enter the Data
2 - Display The data
3 - Search The Company
4 - Delete Some info
Choice :........3
Do U want to search by Name , email id , phone or fax
U want to search the contacts by
0 - Quit
1 - Name
2 - email_id
3 - phone
4 - fax
Choice :........2
Enter the Email to be searched loan at money.com
(('ABN amro', 'loan at money.com', '456', '654'),)
U want to search the contacts by
0 - Quit
1 - Name
2 - email_id
3 - phone
4 - fax
Choice :........2
Enter the Email to be searched loan
()
U want to search the contacts by
0 - Quit
1 - Name
2 - email_id
3 - phone
4 - fax
Choice :........
--- Kent Johnson <kent37 at tds.net> wrote:
> John Joseph wrote:
> > Hi
> > Thanks to Allan,Danny,Pujo
> > I did my simple python script for MySQL ,
> the
> > scripts add the data , and search for the data and
> > display
> > I have problem in searching email id
> ,ie
> > If search for the something at some , I will not get
> any
> > result , Guidance and advice needed for the
> reason
> > for this behavior
>
> Does it work when you search for other data such as
> name or phone?
>
> Can you show the output from a short run where you
> add a contact,
> display the data and search for an email?
>
> Kent
>
> > I had added my script in this mail
> > Thanks
> > Joseph John
> >
> >
>
*********************************************************
> >
> > """ This program is for to learn
> > how to enter data to MySQL using python
> > How to search
> > not using OOP
> >
> > Have problem in searching email-id
> > Why I do not get correct results when
> > searching email id
> > "@" string search containg "@" gives empty
> > results
> >
> > """
> >
> >
> >
> > import MySQLdb
> >
> > def selecter():
> > choice = None
> > while choice != "0":
> > print \
> > """
> > Data Base Entry for the Testing Env
> > 0 - Quit
> > 1 - Enter the Data
> > 2 - Display The data
> > 3 - Search The Company
> > """
> > choice = raw_input("Choice :........")
> > print
> >
> > if choice == "0":
> > print "Good Bye ..."
> > elif choice == "1":
> > dataentry()
> >
> > elif choice == "2":
> > datashow()
> > elif choice == "3":
> > datasearch()
> >
> >
> >
> > def dataentry():
> > name = raw_input("Enter the name of the company
> ")
> > email_id = raw_input("\n Enter the email ID : ")
> > phone_no = raw_input("Enter the Phone No : ")
> > fax_no = raw_input("\n Enter the fax no : ")
> >
> > db = MySQLdb.connect(host="localhost",user =
> "john",
> > passwd = "asdlkj", db = 'learnpython')
> > entry = db.cursor()
> > #entry.execute("""INSERT INTO contact
> > """,(name,email_id,phone_no,fax_no,))
> > entry.execute("""INSERT INTO
> > contact(name,email_id,phone_no,fax_no) VALUES
> > (%s,%s,%s,%s)""",(name,email_id,phone_no,fax_no,))
> > print name , email_id , fax_no, phone_no
> >
> >
> >
> >
> > def datashow():
> > db = MySQLdb.connect(host="localhost",user =
> "john",
> > passwd = "asdlkj", db = 'learnpython')
> > entry = db.cursor()
> > entry.execute("SELECT * from contact")
> > p = entry.fetchall()
> > print p
> >
> > def datasearch():
> > print "Do U want to search by Name , email id ,
> phone
> > or fax "
> > choice = None
> > while choice != "0":
> > print \
> > """
> > U want to search the contacts by
> > 0 - Quit
> > 1 - Name
> > 2 - email_id
> > 3 - phone
> > 4 - fax
> > """
> > choice = raw_input("Choice :........")
> > print
> >
> > if choice == "0":
> > print "Good Bye ..."
> > elif choice == "1":
> > searchbyname()
> >
> > elif choice == "2":
> > searchbyemail()
> >
> > elif choice == "3":
> > searchbyphone()
> > elif choice == "4":
> > searchbyfax()
> >
> > def searchbyname():
> > s_name = raw_input("Enter the name to be searched
> ")
> > db = MySQLdb.connect(host="localhost",user =
> "john",
> > passwd = "asdlkj", db = 'learnpython')
> > entry = db.cursor()
> > entry.execute("""SELECT * FROM contact WHERE name
> =
> > %s""", (s_name,))
> > p = entry.fetchall()
> > print p
> >
> > def searchbyemail():
> > s_email = raw_input("Enter the Email to be
> searched
> > ")
> > db = MySQLdb.connect(host="localhost",user =
> "john",
> > passwd = "asdlkj", db = 'learnpython')
> > entry = db.cursor()
> > entry.execute("""SELECT * FROM contact WHERE
> email_id
> > = %s""", (s_email,))
> > p = entry.fetchall()
> > print p
> >
> >
> > def searchbyphone():
> > s_phone= raw_input("Enter the Phone no to be
> > searched ")
> > db = MySQLdb.connect(host="localhost",user =
> "john",
> > passwd = "asdlkj", db = 'learnpython')
> > entry = db.cursor()
> > entry.execute("""SELECT * FROM contact WHERE
> phone_no
> > = %s""", (s_phone,))
> > p = entry.fetchall()
> > print p
> >
> >
> >
> > def searchbyfax():
> > s_fax = raw_input("Enter the FAX no to be
> searched
> > ")
> > db = MySQLdb.connect(host="localhost",user =
> "john",
> > passwd = "asdlkj", db = 'learnpython')
> > entry = db.cursor()
> > entry.execute("""SELECT * FROM contact WHERE
> fax_no =
> > %s""", (s_fax,))
> > p = entry.fetchall()
> > print p
> >
> > selecter()
> >
> >
> >
> >
> >
> >
>
___________________________________________________________
>
>
=== message truncated ===
___________________________________________________________
To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre. http://uk.security.yahoo.com
More information about the Tutor
mailing list