04.08.2014 Views

o_18ufhmfmq19t513t3lgmn5l1qa8a.pdf

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

494 CHAPTER 26 ■ PROJECT 7: YOUR OWN BULLETIN BOARD<br />

import psycopg<br />

conn = psycopg.connect('dbname=foo user=bar')<br />

curs = conn.cursor()<br />

import cgi, sys<br />

form = cgi.FieldStorage()<br />

reply_to = form.getvalue('reply_to')<br />

print """<br />

<br />

<br />

Compose Message<br />

<br />

<br />

Compose Message<br />

<br />

"""<br />

subject = ''<br />

if reply_to is not None:<br />

print '' % reply_to<br />

curs.execute('SELECT subject FROM messages WHERE id = %s' % reply_to)<br />

subject = curs.fetchone()[0]<br />

if not subject.startswith('Re: '):<br />

subject = 'Re: ' + subject<br />

print """<br />

Subject:<br />

<br />

Sender:<br />

<br />

Message:<br />

<br />

<br />

<br />

<br />

Back to the main page'<br />

<br />

<br />

""" % subject<br />

save.cgi<br />

Now on to the final script. The save script will receive information about a message (from the<br />

form generated by edit.cgi) and will store it in the database. That means using an SQL insert

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!