mysql> create table name(
-> name varchar(255),
-> password varchar(255)
-> );
Query OK, 0 rows affected (0.07 sec)
#!/usr/bin/perl -- use strict; use utf8; use warnings; use CGI; use DBI; my $q = new CGI; my $param1 = $q->param('name'); my $param2 = $q->param('password'); print "Content-type:text/html\n\n"; print "<html>\n"; print "<head></head>\n"; print "<form action=\"/cgi-bin/test2.cgi\">"; print "<label for=\"name\">お名前:</label>"; print "$param1<br>"; print "<label for=\"password\">パスワード:</label>"; print "$param2<br>"; print "<input type=\"submit\" value=\"送信\">"; print "</form>"; print "</html>"; my $user = 'root'; my $passwd = ''; my $db = DBI->connect('DBI:mysql:test:localhost', $user, $passwd); my $sth = $db->prepare("INSERT INTO name(name, password) VALUES (?, ?)"); # $db->do("set names utf8"); $sth->execute($param1, $param2); $sth->finish; $db->disconnect; print("finish\n");
mysql> select * from name;
Empty set (0.00 sec)
mysql> select * from name;
+——+———-+
| name | password |
+——+———-+
| hoge | hogehoge |
+——+———-+
1 row in set (0.00 sec)