【发布时间】:2014-03-04 18:53:26
【问题描述】:
我正在构建一个用于智能手机的非常基本的 html 网站,看起来像这样
<body>
Some Text
<form name="input" action="query.php" method="get">
Search: <input type="text" name="search">
<input type="submit" value="Submit">
</form>
</body>
然后在 query.php 我有这个
select ProductName, PalletSpace, Quantity, TransactionDate from Table1
having Table1.PalletSpace='B005E';
如何将两者联系起来,以便将输入到搜索框中的文本插入到查询中(其中显示 B005E?)?
编辑: query.php 现在包含以下内容:
<?
$username="xxx";
$password="xxx";
$database="xxx";
$con = mysqli_connect("xxx", "xxx", "xxx", "xxx");
$result = mysqli_query($con, "SELECT ProductName, PalletSpace, Quantity, TransactionDate FROM ProductTrans
WHERE ProductName = ($_REQUEST["search"])");
echo "<table border='1'>
<tr>
<th>Product Code</th>
<th>Pallet Space</th>
<th>Quantity</th>
<th>Date</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['ProductName'] . "</td>";
echo "<td>" . $row['PalletSpace'] . "</td>";
echo "<td>" . $row['Quantity'] . "</td>";
echo "<td>" . $row['TransactionDate'] . "</td>";
echo "</tr>";
}
echo "</table>";
?>
query.php 和 html 文件(仍然相同)在同一个目录中。但是,当我尝试搜索时,它给了我这个错误
Parse error: syntax error, unexpected '"', expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/u921305435/public_html/query.php on line 11
【问题讨论】:
-
你可以试试这个。从具有 Table1.PalletSpace="$_REQUEST['search']"; 的 Table1 中选择 ProductName、PalletSpace、Quantity、TransactionDate