CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
form content to database

 



cspgirl
Deleted

Jul 12, 2000, 1:10 AM

Post #1 of 4 (429 views)
form content to database Can't Post

are there any example that show how to post form content to database?

thanks in advance.


abockover
Deleted

Jul 12, 2000, 9:44 PM

Post #2 of 4 (429 views)
Re: form content to database [In reply to] Can't Post

Hi,

I wanted to know the same thing (i think). Have a user submit information to a script and have it written to an external file (DataBase).

Below is a pasted reply, the most helpful one to me.

---------------------------------------------
Use This At the top of your script
########################################
read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@cgiPairs = split(/&/,$buffer);
foreach $cgiPair (@cgiPairs)
{
($name,$value) = split(/=/,$cgiPair);
$value =~ s/\+/ /g;
$value =~ s/%(..)/pack("c",hex($1))/ge;
$form{$name} .= "\0" if (defined($form{$name}));
$form{$name} .= "$value";
}
########################################

This code stores the form values into $form{'value'}.

Now name your forms. For the banner source I'd name the form "bsource". Then the value is stored into $form{'bsource'}. Make sure you point the form action to your script also.

Now open the data file.

open(DB, ">>/full/path/to/file.db");
print DB "$form{'burl'}|$form{'bsource'}|so on|and so on|";
close(DB);

The >> means to append (write to the end of the file), you can also use > to overwrite and < to simply read only.

That's it.

perlkid

[This message has been edited by perlkid (edited 07-03-2000).]
--------------------------------------------

Hope this helps,
Contact perlKid for more help!

Aaron


cspgirl
Deleted

Jul 13, 2000, 10:12 AM

Post #3 of 4 (429 views)
Re: form content to database [In reply to] Can't Post

thanks for reply, if i want to read from the database, how should i go about?

thanks in advance



monocle
User

Jul 13, 2000, 11:09 AM

Post #4 of 4 (429 views)
Re: form content to database [In reply to] Can't Post

To read it use:
open(DB, "</full/path/to/file.db");
@LINES = <DB>
close(DB);

@LINES now contains each line of the DB. you can step through @lines in a number of ways to read each line of the DB looking for what you want. A simple example would be:
foreach $line(@LINES){
($item1,$item2,$item3) = split(/|/,$line);
#DO SOME STUFF WITH THE ITEMS PULLED FROM LINE
}

hope this helps


------------------
Monocle
Hear great techno music by Monocle at http://www.mp3.com/monocle. CD now on sale!


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives