<HTML> <HEAD> <META HTTP-EQUIV="Content-Type" CONTENT="text/html;CHARSET=UTF-8"> <TITLE>Connect MySQL(Perl) 1</TITLE> </HEAD> <BODY> <FORM ACTION="/cgi-bin/connectDB3.cgi" METHOD="get" ENCTYPE="application/x-www-form-urlencoded"> num :<INPUT TYPE="TEXT" NAME="num" SIZE="4"><BR> host_name :<INPUT TYPE="TEXT" NAME="host_name" SIZE="12"><BR> ip_address:<INPUT TYPE="TEXT" NAME="ip_address" SIZE="24"><BR> <INPUT TYPE="hidden" name="command" value="insert"> <INPUT TYPE="SUBMIT" NAME="Submit" VALUE="実行"><BR> </FORM> </BODY> </HTML>
connectDB3.cgi
#!/usr/bin/perl use DBI; $user = '[user]'; $passwd = '[pass]'; $db = DBI->connect('DBI:mysql:sa:localhost', $user, $passwd); if( $ENV{'REQUEST_METHOD'} eq "GET" ) { $std = $ENV{'QUERY_STRING'}; } else { read( STDIN, $std, $ENV{'CONTENT_LENGTH'} ); } print "Content-Type: text/html\n\n\n"; print <<HEADER; <html> <head> <META HTTP-EQUIV="Content-Type" CONTENT="text/html;CHARSET=UTF-8"> <title>Connect MySQL(Perl) 2</title> </head> <body> HEADER print "Method :", $ENV{'REQUEST_METHOD'},"<br>\n"; print "Data :", $std, "<br>\n"; print "<br>"; my @pairs = split(/&/,$std); foreach $pair (@pairs){ my($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; # print "$name : $value<br>"; $form{$name} = $value; print "\$form{$name} = $value<br>" } print "<br>"; if($form{command} eq 'insert'){ if($form{num} eq '' || $form{host_name} eq '' || $form{ip_address} eq ''){ print "登録できません"; }else{ $sth = $db->prepare("INSERT INTO server_list (num,host_name,ip_address) VALUES ('$form{num}','$form{host_name}','$form{ip_address}')"); $sth->execute; print "登録完了"; $sth->finish; } } $db->disconnect; print <<FOOTER; </body> </html> FOOTER
0 件のコメント:
コメントを投稿