Mark Kelly Mark Kelly - 10 months ago 64
Python Question

Processing form data with a Python CGI Script

Can anyone point out where I am going wrong here. I have two scripts, one for the form and the other for the processing. It looks correct but after two hours of staring at it I cannot see where I am going wrong.
Here are the two scripts, they are very short so please take a look at it.

The Form:

import os
import cgi
import cgitb

print("Content-Type: text/html\n\n")

<meta charset="utf-8">
<title>Marks Sonitus Practice</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Practice">
<meta name="author" content="CGI Practice">
<form action="" method="post">
<html><span> First &nbsp;&nbsp;&nbsp;</span></label>
<input type="text" name="firstname"/>
<input type="submit" name ="submitname" value="Submit Name"></form>

The script to process the form:

import os
import cgi
import cgitb

file_name = "/var/www/cgi-bin/practice/"
f = os.path.abspath(os.path.join(file_name))
print"This file could not be found!"
form = cgi.FieldStorage(f)
firstname = form.getvalue('firstname')
print firstname

Can anyone show me where I am going wrong with this?


Well thats simple in your form replace the action=process_data.pyto action=http://localhost/cgi-bin/practice/ or may be action=http://localhost/cgi-bin/practice/ whatever the name of that script is.