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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate:
Allow user to edit own record



Oct 4, 2004, 7:22 AM

Post #1 of 3 (515 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:


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

$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>
if ($input{'database'} eq ''){

open (ORGDB,"<$database");
@ODB=sort <ORGDB>;
close (ORGDB);

print <<"EOF";
<table bgcolor='#eeeeee' border=0 cellpadding=2 cellspacing=0>
<TR align=center valign=top>
<td colspan=3><b>Actions</b></td><td>&nbsp;&nbsp;</td><td><b>Name<b></td></tr>
<TR></td><td colspan="3"> </td></TR>

foreach $rec (@ODB){
print "
<TR><td bgcolor='#eeeeee' class='tnav'><a href='$a&b=$b&c=$c'><b>Edit</b></a>
</td><td></td><td bgcolor='#eeeeee' class='tnav'>
print "</td><td> </td><td>$a $b</td></TR>\n";
print "</table>\n";

The Edit Record Script

&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="" 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">

# 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;



Oct 5, 2004, 11:20 PM

Post #2 of 3 (509 views)
Re: [eejay] Allow user to edit own record [In reply to] Can't Post

Its definetly possible. All you need is a sort of login page where the user enters all the data needed to validate they are the correct person, name and password I assume.

The form sends the name and password to a script and does a check pretty much like you already have in your script. If it matches correctly, print out a populated form, if not prompt for a retry or print an error message.


Oct 13, 2004, 2:34 PM

Post #3 of 3 (500 views)
Re: [KevinR] Allow user to edit own record [In reply to] Can't Post

Hi Kevin, been up to my ears in stuff and remembered this. Sorry I didn't get back sooner.

Haven't had time to try it out, though I had a go doing something similar and if was a wash-out.

Hope to get back to it next week. I had thought it would been fairly straight forward but it ain't :-)

I'm no expert so it takes me a bit longer


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

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