dongpangbu4016 2012-04-11 22:19
浏览 31
已采纳

Mysql php多选,排序

hello i am a noob and i am trying to solve this for hours.I try my url to look like this when i select an option.

category.php?cat_id=122&sort=BOOK_ID+ASC

I am trying with this code

<form name=\"myform\" \">
<select name=\"sort\" id=\"sort\" style=\"float: right;\" onChange=\"document.myform.submit();\">
    <option value=\"car_ID desc&cat_id=$_GET[cat_id]\">cars desc</option>
    <option value=\"car_ID ASC&cat_id=$_GET[cat_id]\">cars asc</option>
</select>
</form><p>";
    $sort="$_GET[sort]";
     $stm = "SELECT *
           FROM cars
           where cat_id=$_GET[cat_id]
            ORDER BY $sort";

but the result is this: category.php?sort=car_id+ASC%26cat_id%3D122

Please help...

  • 写回答

2条回答 默认 最新

  • du8980919 2012-04-11 22:27
    关注

    I would do the following:

    <form name=\"myform\" \">
    <input type=\"hidden\" name=\"cat_id\" value=\"$_GET['cat_id']\">
    <select name=\"sort\" id=\"sort\" style=\"float: right;\" onChange=\"document.myform.submit();\">
    
        <option value=\"car_ID desc\">cars desc</option>
        <option value=\"car_ID ASC\">cars asc</option>
    </select>
    </form><p>";
        $sort="$_GET[sort]";
         $stm = "SELECT *
               FROM cars
               where cat_id=$_GET[cat_id]
                ORDER BY $sort";
    

    A couple of notes here. First, this isn't secure AT ALL. I could easily put ";DROP TABLE..." or something else in the get variable. Second, you probably don't want to be using GET at all. I would handle all form input with POST instead.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了