#!C:\Perl\bin\perl
use DBI;
use DBD::mysql;
print "content-type: text/html \n\n";
print '<html>';
print '<body>';
# DBI CONFIG VARIABLES
$host = "localhost";
$database = "t2";
$port = 3308;
$user = "";
$pw = "";
#DATA SOURCE NAME
$dsn = "dbi:mysql:$database:localhost:3306";
# PERL DBI CONNECT (RENAMED HANDLE)
$conn = DBI->connect($dsn, $user, $pw) or die "Unable to connect: $DBI::errstr\n";
$query = 'SELECT * From book';
$query_handle = $conn->prepare($query);
# EXECUTE THE QUERY
$query_handle->execute();
$query_handle->bind_columns(\$id, \$title ,\$author ,\$price, \$stock);
print '<table border="1">';
print '<thead>';
print '<tr>';
print '<td> Id </td>';
print '<td> title</td>';
print '<td> Author </td>';
print '<td> price</td>';
print '<td> Stock </td>';
print '<td> Buy </td>';
print '</tr>';
print '</thead>';
while($query_handle->fetch()) {
print '<tr>';
print '<td>';
print $id;
print '<td\>';
print '<td>';
print $title;
print '<td\>';
print '<td>';
print $author;
print '<td\>';
print '<td>';
print $price;
print '<td\>';
print '<td>';
print $stock;
print '<td\>';
print '<td>';
if ($stock ne '0')
{
print '<form name="form1" action = "http://localhost/t3/buyBook.pl" method="get">';
print '<input type="hidden" name="buy_id" value="'.$id.'"';
print '<input type="submit" name="buy" value="Buy"';
print '<form\>'
}else
{
print '<input type="submit" name="buy" disabled="disabled" value="Buy"';
}
print '<td\>';
print '<tr\>';
}
print '</table>';
print '<form name="form2" action="http://localhost/t3/search_book.pl" method="get ">';
print '<br/>';
print 'Search for book by:';
print '<br/>';
print '<input type="radio" name="searchBy" value="Title"> Title <br/>';
print '<input type="radio" name="searchBy" value="Author"> Author <br/>';
print '<input type="text" name="search_book" >';
print '<br/>';
print '<input type="submit" name="search" value="Search">';
print '</form>';
print '<body/>';
print '<html/>';
这是按下任意2个提交按钮时显示的网址: http://localhost/tema3/buyBook.pl?buy_id=7505&buy_id=2&buy_id=12195&search_book=&search=Search
知道怎么解决这个问题吗? 安德鲁
答案 0 :(得分:1)
我认为我们在这里遇到的问题是你错误地关闭了标签。这导致第一个<form>
“抓住”它下面的所有参数。尝试修复以下内容:
print '</form>'; ## this is correct closing tag for a form
</form>
和<form\>
不是一回事。 <form\>
将打开新表单而不是关闭。事实上,它不会做任何事情,因为不允许使用嵌套表格。
您还应该在表格单元格和行的末尾使用</td>
和</tr>
标记。