0

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 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

thank you that solved it,thank you very much,ok i will use post.thanks for the advice.
1

Your problem is here:

<option value=\"car_ID desc&cat_id=$_GET[cat_id]\">cars desc</option>

You probably want:

<option value=\"cat_id=$_GET[cat_id]&car_ID desc\">cars desc</option>

That said, I'm not sure where your variable car_ID is coming from, and the space between car_ID and 'desc' will cause a problem with your url.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.