我想在我的sql查询中使用post变量值来按照用户选择的顺序对数据进行排序。该表可以正确显示相应的字段,但值不会排序。在mysql查询中的post变量
我知道这是受sql注入,但是,我在我的本地服务器上进行培训的目的。
<?php
$sort_in = $_POST['SortIn'];
$sql = 'select * from db.Runner order by "'.$_POST['SortIn'].'"';
$result = mysql_query($sql, $con);
if($result)
{
echo "<table border = '1'>
<tr>
<th>RunnerID</th>
<th>EventID</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr><td>";
echo $row['RunnerID'];
echo "</td><td>";
echo $row['EventID'];
echo "</td><td>";
</tr>";
}
echo "</table>";
?>
如果你是为了培训目的而做的,你应该抛弃陈旧/不推荐使用的mysql _ *()函数,并至少使用mysqli或PDO进行学习。 –