[Tutor] sending to file

Alan Gauld alan.gauld at btinternet.com
Sat Jul 18 00:27:32 CEST 2009


<keithabt at beyondbb.com> wrote

>I have a form and script that works. I can enter values into the fields, 
>however
> the data will not show up on the server in the text file. The properties 
> for the
> file is 0777. Can the form cause this problem?

Does the problem only occur when running it on the web server
or does it occur if you run it as yourself?

Do you know where the file is trying to write to?
Is it the cgi-bin folder or the root folder?
What are the permissions of the folder?
777 is probably a bad idea! But let's get the file created first and worry
about security later! :-)

> <form method="post" 
> action="http://web.nmsu.edu/~keithabt/cgi-bin/07_index.cgi">
> <UL><I Align="center">Please feel out the entire form:</I></UL>
> <center><table width="50%" >
> <TR><TD align=right width="20%">Name:</TD>
>    <TD><input type=text Name=name size=50 value="name"></TD></TR>
> <TR><TD align=right> Email Address:</TD>
> <TD><input type=text Name=email size=50 value="email"></TD></TR>
> <TR><TD align=right> Mailing Address:</TD>
> <TD><input type=text NAME=address size=50 value="address"></TD></TR>
> <TR><TD align=right> Telephone Number:</TD>
>    <TD><input type=text NAME=telephone size=50 
> value="telephone"></TD></TR>
> <TD><input type="submit" name="submit" value="Submit:"></TD></TR>
> </table></center>
> </form>
> </body>
> </html>
> """
> fileName = "requests.txt"
> # Create instance of FieldStorage
> Form = cgi.FieldStorage()
>
> # Get data from fields
> if Form and Form['submit'].value == "Submit":
> the_name = Form.getvalue('name')
> the_email = Form.getvalue('email')
> the_address = Form.getvalue('address')
> the_telephone = Form.getvalue('telephone')
>
>
> IpAddress = cgi.escape(os.environ["REMOTE_ADDR"]);
> Time = "(time.localtime()):", time.asctime(time.localtime())
>
> entry = name + '|' + email + '|' + address + '|' + telephone + '|' +
> IpAddress
> + '|' + Time + "\n"

We'll have more success if you send us the real code.
The variables here don't match those above...

>
> Outfile=open("fileName", "a")
> Outfile.write(entry)
> Outfile.close()


HTH,


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/ 




More information about the Tutor mailing list