我想创建一个脚本,选择给定的任期和城市给定的MySQL列中的所有用户。该城市将针对会员,但每个会员可以有3或4个不同的职位(调酒师,服务员,主持人等)。我试图使用的代码在下面,但是,它给了我一个错误。如果您需要更多信息,请与我们联系。谢谢!mysql_query使用LIKE时返回错误
Could not find staff: Unknown column 'Bartender' in 'where clause'
<?php
$perpage = 15;
$city = $_GET['city'];
$type = $_GET['type'];
if(isset($_GET["page"]))
{
$page = intval($_GET["page"]);
}
else
{
$page = 1;
}
$calc = $perpage * $page;
$start = $calc - $perpage;
$result = mysql_query("SELECT * FROM staff WHERE titles LIKE $type AND city=$city LIMIT $start, $perpage");
$rows = mysql_num_rows($result);
if($rows)
{
$i = 0;
while($post = mysql_fetch_array($result))
{
?>
<tr style="background-color: #cccccc;">
<td style="font-weight: bold;font-family: arial;"><?php echo $post["staffnum"]; ?> >> <?php echo $post["titles"]; ?></td>
</tr>
<tr>
<td style="font-family: arial;padding-left: 20px;"><?php echo $post["abt1"]; ?></td>
</tr>
<?php
}
} else {
die('Could not find staff: ' . mysql_error());
}
?>
'喜欢\ “$型\”'。但你需要修复SQL注入使用PDO准备 –
请发布员工的表定义。 – ethrbunny