请问这个PERL该怎么写?我是写asp的能帮我写一个吗?最好要有数据库的。

luobutou 2003-12-12 10:53:52

<form name="form1" method="post" action="test.pl">
<tr>
<td> </td>
<td>姓名:
<input name="username" type="text" size="25"> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>电话:
<input name="phone1" type="text" size="3">
-
<input name="phone2" type="text" size="8">
-
<input name="phone3" type="text" size="5"></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>公司:
<input name="corp" type="text" size="25"></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>职务:
<input name="business" type="text" size="25"></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>               
<input type="submit" name="Submit" value="提交"></td>
<td> </td>
</tr>
</form>
</table>
帮我写一个呀谢谢!
...全文
25 1 打赏 收藏 举报
写回复
1 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
leebx 2003-12-12
把上面的action="test.pl"改为action="test.cgi",是用perl写的CGI程序,数据库用的是MYSQL.
database:user
table:userinfo表结构:
username varchar(30);
phone varchar(20);
crop varchar(50);
business varchar(50);

test.cgi文件:
#!/usr/bin/perl
my %in;
&ReadParse();
$| = 1;
use DBI;
my $database = "user";
my $data_source = "DBI:mysql:$database";
my $username = "";
my $passwords = "";
my $dbh = DBI->connect( $data_source, $username, $passwords) or die "Cant connect to $data_source";
$username=$in{'username'};
$phone1=$in{'phone1'};
$phone2=$in{'phone2'};
$phone3=$in{'phone3'};
$phone="$phone1-$phone2-$phone3";
$corp=$in{'corp'};
$business=$in{'business'};

$Statement="insert into userinto(username,phone,crop,business) values (\"$username\",\"$phone\",\"$crop\",\"$business\");";
$Sth=$dbh->prepare($Statement);
$Sth->execute();
$Sth->finish();
$dbh->disconnect;

sub ReadParse
{
local $a = $_[0] ? $_[0] : \%in;
local $i;
local $meth = $_[1] ? $_[1] : $ENV{'REQUEST_METHOD'};
undef($in);
if ($meth eq 'POST') {
read(STDIN, $in, $ENV{'CONTENT_LENGTH'});
}
if ($ENV{'QUERY_STRING'}) {
if ($in) { $in .= "&".$ENV{'QUERY_STRING'}; }
else { $in = $ENV{'QUERY_STRING'}; }
}
@in = split(/\&/, $in);
foreach $i (@in) {
local ($k, $v) = split(/=/, $i, 2);
$k =~ s/\+/ /g; $k =~ s/%(..)/pack("c",hex($1))/ge;
$v =~ s/\+/ /g; $v =~ s/%(..)/pack("c",hex($1))/ge;
$a->{$k} = defined($a->{$k}) ? $a->{$k}."\0".$v : $v;
}
}
  • 打赏
  • 举报
回复
相关推荐
发帖
CGI
加入

2198

社区成员

Web 开发 CGI
申请成为版主
帖子事件
创建了帖子
2003-12-12 10:53
社区公告
暂无公告