30: conn.close()
- Save the file and then exit the editor.
- Copy the file to the /usr/lib/cgi-bin folder and assign it permissions to run,
like this:
Click here to view code image
pi@raspberrypi ~ $ sudo cp script2204.cgi /usr/lib/cgi-bin
pi@raspberrypi ~ $ sudo chmod +x /usr/lib/cgi-bin/script2204.cgi - View the script2204.cgi file in your web browser client. You should see the
results from the data you entered into the employees table in Hour 21 (see Figure
22.4).
FIGURE 22.4 The results from the script2204.cgi program.
The script2204.cgi file uses a slightly different method for adding the HTML code required to
display the output. Instead of using a separate print() method for each HTML element in the
document, in the script2204.cgi file, you used the triple-quote method of creating one long
string value (lines 4 through 14). This helps cut down on some of the typing, and makes it a little
easier to follow the HTML code embedded in the Python code.
Watch Out!: Web Database Security
The script2204.cgi script embeds the user ID and password for your MySQL database
into a file that everyone on the server can read. For testing on a personal Raspberry Pi
system, this is not a problem, but on a real system shared by others, doing this isn’t
such a great idea. One solution is to restrict access to the file to only the Apache web
server user account. For the Raspberry Pi, the Apache web server runs as the www-