Click to See Complete Forum and Search --> : edit the content of a table using cgi


butlerps
10-08-2004, 02:18 AM
hello

I desperately need someones/everyones help in trying to figure out whether i can alter the content of a table on one of my pages i am designing for a friend using cgi. I found a php script that i thought had answered my prayers,
http://www.webdeveloper.com/forum/showthread.php?s=&postid=258063 BUT unfortunately my host does not support php :-(. It is only a small table 6 columns by 7 rows so i want to avoid using a database. I know there is scripts out there that you can use for altering the whole html, but my friend is not that computer literate, so i want to avoid her getting too confused. If anyone out there can help me with this i'd be indebted.

Cheers

Philip

silent11
10-08-2004, 09:31 AM
Just create a file named 'params.inc' in the same dir as this script and make sure the script has access to write to it.


#!/usr/bin/perl
use CGI::Pretty qw(:standard *table);
use CGI::Carp 'fatalsToBrowser';

print header, start_html('field editor');


if (param('action') eq 'edit'){
slurp();
edit_html();
exit;
}
if (param('action') eq 'save'){
save_fields();
view_html();
exit;
}
else {
slurp();
view_html();
exit;
}


################ S U B S ################

sub slurp{
open (FILE,"<params.inc") || die $!;
restore_parameters(FILE);
close (FILE);
}


sub view_html{
print start_table({-border=>1});
for ('a' .. 'g'){
my $row = $_;
print Tr( map { td( param( $row . $_ ) ) } (1..6) );
}
print end_table, start_form, submit('action','edit'), end_form;
}

sub edit_html{
print start_table({-border=>1}), start_form;
for ('a' .. 'g'){
my $row = $_;
print Tr( map { td( textfield( $row . $_ ,param( $row . $_ ) ) ) } (1..6) );
}
print end_table, submit('action','save'), end_form;
}

sub save_fields {
open (FILE,">params.inc") || die $!;
save_parameters(FILE) || die $!;
close (FILE);
}



params.ini


a1=Value in row a 1
a2=Value in row a 2
a3=Value in row a 3
a4=Value in row a 4
a5=Value in row a 5
a6=Value in row a 6
b1=Value in row b 1
b2=Value in row b 2
b3=Value in row b 3
b4=Value in row b 4
b5=Value in row b 5
b6=Value in row b 6
c1=Value in row c 1
c2=Value in row c 2
c3=Value in row c 3
c4=Value in row c 4
c5=Value in row c 5
c6=Value in row c 6
d1=Value in row d 1
d2=Value in row d 2
d3=Value in row d 3
d4=Value in row d 4
d5=Value in row d 5
d6=Value in row d 6
e1=Value in row e 1
e2=Value in row e 2
e3=Value in row e 3
e4=Value in row e 4
e5=Value in row e 5
e6=Value in row e 6
f1=Value in row f 1
f2=Value in row f 2
f3=Value in row f 3
f4=Value in row f 4
f5=Value in row f 5
f6=Value in row f 6
g1=Value in row g 1
g2=Value in row g 2
g3=Value in row g 3
g4=Value in row g 4
g5=Value in row g 5
g6=Value in row g 6



butlerps - I sent you a private message....

butlerps
10-08-2004, 09:56 AM
hey silent11
Thanks so much for the reply, we (you that is) are almost there. the cgi you have created is going to be perfect for my admin (WOW we've just had an earthquake, so sorry if i make any typo's, my hands are a little shaky!!!!!) sorry..... yeah that is going to be great for my admin page, now what i need to be able to do is somehow incert the table into an existing html document, can you help me out here .

Cheers
Philip


p.s I've sent you a private message

CyCo
10-08-2004, 11:13 AM
Just create a file named 'params.inc' in the same dir as this script and make sure the script has access to write to it.
Nice one, silent11 ;)

butlerps
10-08-2004, 11:19 AM
hey CyCo
I've got the script up and running fine
www.whatthebutlersaw.com/ino/table/table.cgi
but now i need to figure how to display the table data in my existing html document. I'm assuming somehow i can use javascript for that inside the html, but i am clueless at all this (I can understand WHAT the code does but lack the knowledge to understand HOW it does it.

Anyway i agree with you 100%: Nice one silent11;)

CyCo
10-08-2004, 11:24 AM
You could use an iframe on the page and set the src of the iframe to the script.

silent11
10-08-2004, 12:03 PM
Originally posted by butlerps
hey CyCo
I've got the script up and running fine
www.whatthebutlersaw.com/ino/table/table.cgi
but now i need to figure how to display the table data in my existing html document.



Problem solved *off-line* :)