LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-20-2006, 06:34 PM   #1
metalx1000
Member
 
Registered: Jun 2006
Distribution: Debian
Posts: 112

Rep: Reputation: 16
Question Saving Info on a website.


I need to save a users input to a file on my server. I'm running Apache on my Linux box and I have been able to save the out put of my CGI shell scripts to files. But, I don't know how to save user input.

Should I use a Shell Script or can I do it with a HTML Form? And how would I go about doing it.

Thanks
 
Old 09-20-2006, 07:00 PM   #2
dinojerm
Member
 
Registered: Apr 2004
Location: NJ,US
Distribution: Debian Sid
Posts: 33

Rep: Reputation: 15
If you want the data to be written to your server, you need a server-side script; the data can be sent by an html form to the script.
Parsing the cgi data (so that your script can process the data input by the user) is possible using a shell script, but is simpler in perl or php.
An example of a simple perl cgi script that will append the contents of a html form's text box to the file "txtdata":
Code:
#!/usr/bin/perl
use CGI::Pretty ':standard';
my $txt=param('txt'); #Gets the data from the textarea named "txt"
print "Content-type: text/html\n\n";
print '<html>
<head><title>Foo</title></head>
<body> ';
if (!$txt) { #This page wasn't sent any text, so it prints a form for user to enter it
print 'Enter Text: <br>
<form action="" method="post">
<textarea name="txt" rows="10" cols="42"></textarea><br>
<input type="submit" value="Submit">
</form>
';
} else { #Appends the contents of $txt (sent by form) to file
        open(F,'>>txtdata');
        print F "$txt\n";
        print "Text Written";
        close F;
}
print '
</body>
</html>';
Other form elements can be processed in a similar manner, depending on your needs.

Last edited by dinojerm; 09-20-2006 at 07:02 PM.
 
Old 09-20-2006, 07:18 PM   #3
metalx1000
Member
 
Registered: Jun 2006
Distribution: Debian
Posts: 112

Original Poster
Rep: Reputation: 16
Thank you very much

Thanks dinojerm,

That is what I need.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
saving info from koppix twistedrhymes Linux - Newbie 6 06-14-2005 12:02 PM
Info on website design ShakyJake Programming 1 06-13-2005 03:19 PM
Saving info for reinstallation Hanj Linux - Newbie 6 05-05-2005 11:23 AM
failure loading or saving config info for rhn-applet strimp099 Linux - General 0 05-24-2004 11:30 PM
how does a brower get URL address info when the website is hiding it? sirpelidor Programming 3 12-05-2003 09:33 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:28 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration