I have a cgi script that i want the user to type in a keyword in. There is a file keywords.txt that contains keywords. The program will open that file and make it into a list. Then, it should check to user if the keyword the user just entered is in that list. If it is, it will take it to another cgi script, if it is not, it will write it to the file and take it to a different cgi script.
I am having trouble figuring out what variable to use in my IF statement to check if the user-inputed keyword is in the list. Here is what I have so far, like I said my main problem if figuring out how to check if it is in the list and then adding it to the text file.
I am having trouble figuring out what variable to use in my IF statement to check if the user-inputed keyword is in the list. Here is what I have so far, like I said my main problem if figuring out how to check if it is in the list and then adding it to the text file.
#!/usr/bin/env python import cgi import cgitb cgitb.enable() form = cgi.FieldStorage() keyword = form.getvalue('keyword') print 'Content-type: text/html\r\n\r' print '<html>' print '<h1>Please enter a keyword of your choice</h1>' print '<form action="results.cgi" method="post">' print 'Keyword: <input type="text" name="keyword"> <br />' print '<input type="submit" value="Submit" />' print '</form>' print '</html>' #keylist = [] #f = open('keywords.txt', 'rw') #for each in f.readlines(): #keylist.append(each) #if keyword in keylist: #print 'Location: %s' % #Second CGI Script #else: #f.write(keyword) #f.close() #print 'Location: %s' % #Third CGI Script