我想使用 perl 在 mysql DB 中插入表单数据。为此,我制作了 2 个文件,第一个是 html 文件,它接受输入,第二个在 .cgi 文件中,由 html 文件调用以使用插入查询将数据存储在 DB 中.
我面临的问题是我能够从用户那里获取输入,但由于 cgi 文件无法从 html 文件中获取值,因此无法在 DB 中插入值。我也收到语法错误表单提交上的消息..这两个相关吗?
HTML 代码...
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> Report</title>
<h1 style="text-align:center;color:white;background-color:blue" Reports</h1>
<style>
.label
{
float: left;
width:120px;
padding:10px 30px;
<!--font-weight:bold;-->
}
textarea
{
<!--margin-bottom:90px;
margin-top:50px";-->
vertical-align:top;
overflow : auto;
}
.textarea
{
resize :none;
border: none;
width: 100%;
-webkit-box-sizing: border-box; <!-- <=iOS4, <= Android 2.3 */-->
-moz-box-sizing: border-box; <!-- FF1+ -->
-box-sizing: border-box; <!-- Chrome, IE8, Opera, Safari 5.1-->
}
table.table, th.table, td.table
{
border: 1px solid black;
border-collapse: collapse;
padding: 2px;
}
div#box
{
border:1px solid black;
align:center;
width:250px;
height:250px;
padding:10px;
}
span#sub
{
display:block;
font-weight:bold;
text-decoration:underline;
text-align:center;
}
label#main
{
<!--display:block;-->
font-weight:normal;
margin-bottom:10px;
}
textarea#strat
{
border:none;
width:100%;
height:65%;
resize:none;
}
</style>
</head>
<body>
<form action="jaihoshanidevki.cgi" method="post">
<label for="name" class="label">Name</label>
<textarea id="name" rows="1px" cols="20px" style="resize:none" placeholder="Name">sample name</textarea>
<label for="desig" >Designation:</label>
<textarea id="desig" rows="1px" cols="20px" style="resize:none" placeholder="Designation">designation</textarea><br><br><br>
<label for="dept" class="label">Department</label>
<textarea id="dept" rows="2px" cols="20px" style="resize:none" placeholder="Function/Department"> department</textarea>
<label for="date1">Date(YYYY/MM/DD):</label>
<textarea id="date1" rows="1px" cols="14px" style="resize:none" placeholder="Date">2013/05/22</textarea><br><br><br>
<label for="cname" class="label"> Cluster Name</label>
<textarea id="cname" rows="1px" cols="20px" style="resize:none" placeholder="Cluster Name">risk cluster number 1</textarea>
<label for="cnum"> Cluster Number:</label>
<textarea id="cmun" rows="1px" cols="12px" style="resize:none" placeholder="Cluster Number">sample cluster number</textarea><br><br><br>
<p><b>Identification Methodology: (Tick the appropriate option)</b></p>
<input type="checkbox" id="roa"> Already Occured
<input type="checkbox" id="roc"> industry:<br><br>
<label for="date2" class="label">Date of Occurance(DD/MM/YY):</label>
<textarea id="date2" rows="1" cols="10" style="resize:none" placeholder="Date">2013/05/22</textarea><br><br><br>
<label for="other" class="label">Others:(Please specify)</label>
<textarea id="other" rows="2" cols="30" style="resize:none" placeholder="others">sample other</textarea><br><br><br>
<p><b>Preliminary Details(briefly):</b></p>
<label for="desc" class="label">Description</label>
<textarea id="desc" rows="5" cols="50" style="resize:none" placeholder="Risk Description">sample desc</textarea><br><br>
<label for="root" class="label">Root</label>
<textarea id="root" rows="5" cols="50" style="resize:none" placeholder="Cause">sample root</textarea><br><br>
<label for="rqi" class="label">DQI</label>
<textarea id="rqi" rows="5" cols="50" style="resize:none" placeholder="Description and Qualification">sample DQI</textarea><br><br>
<p><b> Category (Tick the appropriate option) :</b></p>
<input type="checkbox" id="stra">Strategic
<input type="checkbox" name="roc">Operational
<input type="checkbox" name="repu">Reputational
<br><br>
<input type="checkbox" name="comp">Compliance
<br><br><br>
<div id="box" align="center">
<label for="strat" id="main"><span id="sub" style="text-align:center">Preliminary Risk Mitigation Strategy:</span>(Report in brief, responsibility & next review date)</label>
<textarea id="strat" rows="5" cols="20" placeholder="Enter Data" >sample strategy</textarea>
</div><br><br>
<input type="submit" id="submit"> <br><br>
</form>
</body>
</html>
.cgi 文件..
#!/usr/sbin/perl
print "Content-type: text/html\n\n";
use DBI;
use CGI;
use CGI::Carp qw (fatalsToBrowser);
$dbh = DBI->connect("DBI:mysql:database=Demo;host=localhost","mint", "MINT123", {'RaiseError' => 1});
$q = CGI->new;
$query=CGI->new;
$name=$query->param('name');
$desig=$query->param('desig');
$dept=$query->param('dept');
$date1=$query->param('date1');
$cname=$query->param('cname');
$cnum=$query->param('cnum');
#$im=$query->param('name');
$date2=$query->param('date2');
$other=$query->param('other');
$desc=$query->param('desc');
$root=$query->param('root');
$dqi=$query->param('dqi');
#$rc=$query->param('name');
$strat=$query->param('strat');
#print "$name=====uuuuuu";
print $q->header;
# my $dsn = "DBI:mysql:Demo:localhost"; # Data source name
# my $username = "mint"; # User name
# my $password = "MINT123"; # Password
# my $dbh,$sth; # Database and statement handles
# $dbh = DBI->connect($dsn, $username, $password);
$sth = $dbh->prepare("Insert into FIR (name,desig,dept,date1,cname,cnum,im,date2,other,desc,root,dqi,rc,strat) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
$sth->execute($name,$desig,$dept,$date1,$cname,$cnum,check1,$date2,$other,$desc,
$root,$dqi,check2,$strat);
$sth->finish() or die $DBI::errstr;;
#print "hello";
$dbh->disconnect() or die $DBI::errstr;;
对于复选框值,我只是试图将“check1”和“check2”值放入数据库中,这就是为什么我不为它们取参数..
表结构..
该表是空的,它不包含任何数据..
错误信息。
错误信息的第二部分
错误信息的第三部分