当我选择从我的数据库中检索某些数据的选项时,我收到以下错误消息:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1.
为什么?第1行什么都没有? 另外,你能教我如何搜索检索到的数据吗?
实施例。如果我选择选项1" Antal narvaro"然后按确定按钮,以下sql-query将执行:SELECT * FROM mytable WHERE fran = 'besok';
一旦我检索到这些数据,我想进一步在其中搜索某些信息,如姓名,年龄等。否则,我很感激我可以通过在下拉列表中选择选项然后按OK按钮来执行以下SQL查询。
我非常擅长 PHP 和HTML,提前感谢!
<html>
<head>
<title>AiFind</title>
<link rel="stylesheet" href="Style.css">
<script type="text/javascript" src="logic.js"></script>
</head>
<body>
<h1><img src="https://imagizer.imageshack.us/v2/278x186q90/844/k32d.png"
height="70" width="100" alt="Aifind-logo copy"></h1>
</body>
</html>
<?php
include "connection.php";
$sql = "SELECT";
if (isset($_POST['search'])) {
$search_term = mysql_real_escape_string($_POST['search_box']);
switch($_POST['filter']) {
Default:
$sql .= " ";
break;
case 1:
$sql .= " * from mytable WHERE fran = 'Besök'; ";
break;
case 2:
$sql .= " * from mytable WHERE fran = 'Bok'; ";
break;
case 3:
$sql .= " Postort, COUNT(*) FROM mytable WHERE AAA_diam != ";
$sql .= " 'missing' GROUP BY Postort; ";
break;
case 4:
$sql .= " *, COUNT(*) FROM mytable WHERE AAA_diam = 'missing'";
$sql .= " GROUP BY Postort";
break;
case 5:
$sql .= " COUNT(*) AS Antal_over_30 FROM mytable WHERE ";
$sql .= " AAA_diam > 30 AND AAA_diam != 'missing' AND ";
$sql .= " AAA_diam != 'n.a' AND AAA_diam != 'Missing'";
break;
case 6:
$sql .= " COUNT(*) AS Antal_over_30 FROM mytable WHERE ";
$sql .= " AAA_diam > 50 AND AAA_diam != 'missing' AND ";
$sql .= " AAA_diam != 'n.a' AND AAA_diam != 'Missing'";
break;
case 7:
$sql .= "";
break;
}
}
$query = mysql_query($sql) or die(mysql_error());
?>
<!--Sökrutan där sökord matas in -->
<form name="Select_filter" method="POST" action="VGR_data_display.php">
<select id="dropdown" name="filter">
<option value=""></option>
<option value="1">Antal narvaro</option>
<option value="2">Antal franvaro</option>
<option value="3">Antal narvaro: destination</option>
<option value="4">Antal franvaro: destination</option>
<option value="5">Antal A_diam > 3cm</option>
<option value="6">Antal A_diam > 5cm</option>
<option value="7">Antal franvaro: procent</option>
</select>
<!--search bar for search term input -->
<input id="search_box" type="text" name="search_box" value="" />
<input id="submit" type ="submit" name ="search" value ="Ok">
</form>
<table style="margin:auto;" id="table" border='1'>
<tr>
<th>ID</th>
<th>F_ar</th>
<th>Postnr</th>
<th>Postort</th>
<th>Vardgivare</th>
<th>Team</th>
<th>Orsak</th>
<th>Planerat_datum</th>
<th>fran</th>
<th>AAA_diam</th>
</tr>
<?php while($row = mysql_fetch_array($query)) { ?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['F_ar']; ?></td>
<td><?php echo $row['Postnr']; ?></td>
<td><?php echo $row['Postort']; ?></td>
<td><?php echo $row['Vardgivare']; ?></td>
<td><?php echo $row['Team']; ?></td>
<td><?php echo $row['Orsak']; ?></td>
<td><?php echo $row['Planerat_datum']; ?></td>
<td><?php echo $row['fran']; ?></td>
<td><?php echo $row['AAA_diam']; ?></td>
</tr>
<?php } ?>