20251002 search html/search cgi

20251002 search html/search cgi

(search,html)

<html>
<head><title>search</title></head>
<body>
<center><h1><b>データベース初歩</b></h1>
<hr>
<form action=”search.cgi”method=”POST”>
検索キーワード<br>
<input type=”text”name=”kyeword”><br>

<input type=”submit”value=”検索”>
<input type=”reset”value=”リセット”>
</form>
</center>
</body>
</html>

(search.cgi)

#!/usr/bin/perl
BEGIN{$|=1;print “Content-type: text/html\n\n”;open(STDERR,
“>&STDOUT”);}

use CGI;
$query=new CGI;

$kensaku=$query->param(‘kyeword’);

#テキストデータ読み込み###################
open(IN,”<save.txt”);
@data=<IN>;
close(IN);
#################################
print <<END;

<html>
<head>
<title>search</title>
<meta http-equiv=”Content-Type” content=”text/html;
charset=Shift_JIS”>
</head>

<body bgcolor=”#FFFFFF” text=”#000000″>
<div align=”center”>
<h1><b>データベース初歩</b></h1>
</div>

<hr>

END
#配列@dataの中身を#########################
for($i=0;$i<@data;$i++){

@retudata=split(/\t/,$data[$i]);
if($data[$i]=~m/$kensaku/){

#ここが検索したい言葉と@dataの中にある言葉が合致した場合

#その一列@retudataを単語単位でくぎりprint書き出し

print”年:@retudata[0]<br>\n”;
print”月:@retudata[1]<br>\n”;
print”日:@retudata[2]<br>\n”;
print”時:@retudata[3]<br>\n”;
print”分:@retudata[4]<br>\n”;
print”名前:@retudata[5]<br>\n”;
print”住所:@retudata[6]<br>\n”;
print”電話:@retudata[7]<br>\n”;
print”メール:@retudata[8]<br>\n”;
print”<hr>\n”;

}
}
print”</body>\n”;
print”</html>\n”;
exit;

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です