我在 PHP 中开发了表单来搜索 MySQL 数据库,但是无论我如何尝试它仍然无法检索到任何结果。而且我在下面的代码中找不到任何语法错误或其他类似问题,
<?php
$txtkv=$_POST['txtkv'];
$cbgen=$_POST['txtgenerator'];
$cbinsulation=$_POST['txtinsulation'];
$cbclass=$_POST['txtclass'];
$cbairinlet=$_POST['txtairInlet'];
$cbip=$_POST['txtIp'];
// set database server access variables:
$host = "localhost";
$user = "root";
$pass = "";
$db = "nordhavn";
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
mysql_select_db($db) or die ("Unable to select database!");
$query="SELECT Scania.GensetType, Scania.EngineType, Scania.Engine60Hz, Scania.Alternator,NordhavnGenset.MaxKw, NordhavnGenset.MaxKva, Scania.PriceEur
FROM Scania
LEFT JOIN NordhavnGenset ON Scania.Alternator=NordhavnGenset.Alternator
LEFT JOIN Generator ON Generator.Alternator=Scania.Alternator
LEFT JOIN Insulation ON Insulation.Insulation=NordhavnGenset.Insulation
LEFT JOIN Klasse ON Klasse.Klasse=NordhavnGenset.Class
LEFT JOIN AirInletFilter ON AirInletFilter.AirInletFilter=NordhavnGenset.AirInletFilter
LEFT JOIN IP ON IP.IP=NordhavnGenset.Ip
WHERE (NordhavnGenset.MaxKva='".$txtkv."') and (Generator.Alternator='".$cbgen."') and (Insulation.Insulation='".$cbinsulation."') and (Klasse.Klasse='".$cbclass."') and (AirInletFilter.AirInletFilter='".$cbairinlet."') and (IP.IP='".$cbip."')";
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
$i = 0;
if (mysql_num_rows($result) > 0) {
echo "<table cellpadding=10 border=1>
<tr>
<td> Gense Type (Scania.GensetType) </td>
<td> Engine type (Scania.Enginetype) </td>
<td> Engine 60Hz (Scania.Engine60hz)</td>
<td> Alternator (Scania.Alternator and Genrator.Alternator) </td> <td> Max Kw (NordhavnGenset.MaxKw) </td>
<td> Max Kva (NordhavnGenset.MaxKva)</td>
<td> Price Euro (Scania.PriceEur) </td>
</tr>";
while(($row = mysql_fetch_row($result)) !== false) {
$i++;
echo "<tr class=\"d".($i & 1)."\">";
echo "<td>"."<center>".$row[1]."</center>"."</td>";
echo "<td>"."<center>".$row[2]."</center>"."</td>";
echo "<td>"."<center>".$row[3]."</center>"."</td>";
echo "<td>"."<center>".$row[4]."</center>"."</td>";
echo "<td>"."<center>".$row[5]."</center>"."</td>";
echo "<td>"."<center>".$row[6]."</center>"."</td>";
echo "<td>"."<center>".$row[7]."</center>"."</td>";
echo "<td>"."<center>".$row[8]."</center>"."</td>";
echo "<td>"."<center>".$row[9]."</center>"."</td>";
echo "<td>"."<center>".$row[10]."</center>"."</td>";
echo "<td>"."<center>".$row[11]."</center>"."</td>";
echo "</tr>";
}
echo "</table>";
}else {
echo "No rows found!";
}
mysql_free_result($result);
mysql_close($connection);
?>