Using MySQL to populate the form. It loads data one dabase table row per <tr> row. Please don't mind the crude use of the html table (I'll add the CSS later). So, when I open the script it shows all the rows of the table but, If I select one and it goes
to edit_members_2 it only displays data from the first db table row regardless of the one I select in the form. I also tried using a <select> to put the SQL data in the form rather than the way I did this one and added a submit button but the results were
the same. All the link info, subroutine names and variable names etc is purely ficticious (given other names). The reason for the same db table in part two--update with the info in part 1.
my $query;
my $sth;
my $ref;
my $query=new CGI;
my $sub_selecter;
my $id_number=$query->param("id_number");
my $name=$query->param("name");
my $dbh = DBI->connect('connection parameters') or die("Couldn't connect");
#sub re-direct station I have quite a few subroutines in the main file.
if($sub_selecter==1){&edit_something_2($id_number, $name);exit;}
sub edit_something{
print"<h1 align=\"center\">Select a Name to Edit $user_id</h1>";
&htm_header;
print" <table align=\"center\"border=\"2\"width=\"30%\">\n";
print" <form id=\"EP\"method=\"post\"action=\"$ENV{'SCRIPT_NAME'}\">\n";
print" <input type=\"hidden\"name=\"sub_selecter\"value=1>\n";
$sth=$dbh->prepare("SELECT * FROM table_1");
$sth->execute();
while($ref=$sth->fetchrow_hashref()){
print" <tr>\n";
print" <td width=\"100%\"><h2>\n";
print" <input type=\"hidden\"name=\"id_number\"value=\"$ref->{'id_number'}\">\n";
print" <input type=\"hidden\"name=\"name\"value=\"$ref->{'name'}\">\n";
print" <a href=\"javascript:{}\" onclick=\"document.getElementById('EP').submit(); return false;\">$ref->{'name'}</a>\n";
print" </td></h2>\n";
print" </tr>\n";}
print" </form>\n";
print" </table>\n";
}
sub edit_something_2{
print"<h1>Part Two $_[0] $_[1]</h1>\n";
my $dbh = DBI->connect('connection parameters where id_number=$_[0]') or die("Couldn't connect");
$sth=$dbh->prepare("SELECT * FROM table_2");
$sth->execute();
while($ref=$sth->fetchrow_hashref()){
print"$_[0] $_[1]";
}
}