
eejay
Novice
Oct 4, 2004, 7:22 AM
Post #1 of 3
(443 views)
|
|
Allow user to edit own record
|
Can't Post
|
|
Need help please. I've put together an address book in Perl which works good. In the user admin script I can click on the name of a record to edit it and that record appears in a form populated by the record ready for editing. The end field contains a password (unused at the moment). What I want to do is be able to click on a name, and instead of immediately going to the form, bring up a password box so the user can enter their password (held on their record - a hidden field), then the populated form appears. This way a user can edit their own entry without having to contact the admin person. The flat-file database (data.txt) is like this: Smith|John|123 Brown|bill|abc with abc and 123 being the passwords (field "c"). The actual edit script works fine. It's just getting the form populated that I cannot for the life of me figure out. I have tried a number of ways getting nowhere. Any ideas? Or, am I trying to do something that is impossible in PERL? The User Admin script useradm.pl ----------- #!/usr/bin/perl $database = "data.txt"; ## field $c is the password # User Admin print "Content-type: text/html\n\n"; print <<"EOF"; <table border="0" cellpadding="4" cellspacing="0" width="400"> <TR align=center valign=top> <td><b>Admin Center</b></td> </td></tr></table> EOF if ($input{'database'} eq ''){ $db=$database; }else{ $db=$input{'database'}; } open (ORGDB,"<$database"); @ODB=sort <ORGDB>; close (ORGDB); print <<"EOF"; <P> <table bgcolor='#eeeeee' border=0 cellpadding=2 cellspacing=0> <TR align=center valign=top> <td colspan=3><b>Actions</b></td><td> </td><td><b>Name<b></td></tr> <TR></td><td colspan="3"> </td></TR> EOF foreach $rec (@ODB){ chomp($rec); ($a,$b,$c)=split(/\|/,$rec); print " <TR><td bgcolor='#eeeeee' class='tnav'><a href='useredr.pl?a=$a&b=$b&c=$c'><b>Edit</b></a> </td><td></td><td bgcolor='#eeeeee' class='tnav'> \n"; print "</td><td> </td><td>$a $b</td></TR>\n"; } print "</table>\n"; exit ----------- The Edit Record Script useredr.pl ----------- #!/usr/bin/perl &parseform; ## needs to be here to process data from admin ## field c is the password print "Content-type: text/html\n\n"; print <<"EOF"; <b>Edit Record</b> <form action="edit.pl" method="GET"> <input type="hidden" name="a" value="$input{"a"}"> <input type="hidden" name="b" value="$input{"b"}"> <input type="hidden" name="c" value="$input{"c"}"> <table border="0" cellpadding="4" cellspacing="0"> <tr><td>Last Name</td> <td><input type="text" name="na" value="$input{"a"}"></td></tr> <tr><td>First Name</td> <td><input type="text" name="nb" value="$input{"b"}"></td></tr> <td colspan="2" align="center"><input type="Submit" id="btntxt" value="Edit Record"> </td></tr></table> </form> EOF # Parse Form (generic) sub parseform { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); if (length($buffer) < 5) { $buffer = $ENV{QUERY_STRING}; } @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $input{$name} = $value; } } -----------
|