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:
Allow user to edit own record

 



eejay
Novice

Oct 4, 2004, 7:22 AM

Post #1 of 3 (541 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>&nbsp;&nbsp;</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;
}
}


-----------


KevinR
Veteran


Oct 5, 2004, 11:20 PM

Post #2 of 3 (535 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.
-------------------------------------------------


eejay
Novice

Oct 13, 2004, 2:34 PM

Post #3 of 3 (526 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