Forum Moderators: coopster & phranque

Message Too Old, No Replies

Passing parameters to CGI

         

aline

2:15 pm on Jul 20, 2003 (gmt 0)

10+ Year Member



I'm trying to pass parameters from one perl file to the other so that information entered by a user on one form are kept for the next form. My initial code was the following:

print "<font size=\4\"> welcome $ surname $name</font size><br><br> Please choose a username for the site and a password<br><br><br><form action=\"password.pl?id='$id'&unicode='$university'\" method=\"post\" target=\"mainFrame\">Username: <input type=\"text\" name=\"username\" size=\"15\"><br><br><br>
Password: <input type=\"text\" name=\"password\" size=\"15\"><br><br><br><center>
<input type=\"submit\" value=\"Submit\"></form></center>";
}
$id and $university having been captured earlier in the code as
$id=param("id");
$university=param("university");

The password perl file was then the following:
#!c:/perl/bin/perl.exe
use DBI;
$,="\t";
use CGI ":standard";
$username=param("username");
$password=param("password");
$id=param("id");
$unicode=param("unicode");

print"content-type:text/html\n\n";
print"<html>\n";
print"<body bgcolor=\"#990000\"><font color=\"white\">";

$db=DBI->connect("dbi:mysql:administration") or die"\n Error($DBI::err):$DBI::errstr\n";

$update="INSERT into password values('$username','$password','$id','$unicode')";
$s=$db->do($update);
print"<b><font color=\"white\">Database updated</font color></b>";

$s->finish();

$db->disconnect();

This didn't work as the database only recorded $username and $password but not the other two.

It does work if in the first file I use hidden text:
print "<font size=\4\"> welcome $ surname $name</font size><br><br> Please choose a username for the site and a password<br><br><br><form action=\"password.pl\" method=\"post\" target=\"mainFrame\">Username: <input type=\"text\" name=\"username\" size=\"15\"><br><br><br>
Password: <input type=\"text\" name=\"password\" size=\"15\"><br><br><br><center>
<input type=\"hidden\" name=\"id\" value=\"$id\"> <input type=\"hidden\" name=\"unicode\" value=\"$university\"><input type=\"submit\" value=\"Submit\"></form></center>" ;

But I would prefer not to have to do this and pass it as parameters. Could anyone tell me what I did wrong in my first script?

Thank you

ShawnR

2:37 pm on Jul 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



perhaps it is the single quotes in:
id='$id'&unicode='$university'

But putting them in hidden fields is perfectly legitimate (and a more widely used method by far).

Shawn

aline

2:42 pm on Jul 20, 2003 (gmt 0)

10+ Year Member



Thank you!