Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - passing a sort order from page to page
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

passing a sort order from page to page

 Post Reply Post Reply
Author
shanerobinson View Drop Down
Newbie
Newbie


Joined: 21 August 2008
Status: Offline
Points: 17
Post Options Post Options   Thanks (0) Thanks(0)   Quote shanerobinson Quote  Post ReplyReply Direct Link To This Post Topic: passing a sort order from page to page
    Posted: 21 August 2008 at 10:39am
Hi Everyone,

I have set up a page to display records from my database and i have restricted it to show only ten records at a time. I have an option for the user to select a sort order for the records which works just fine, However when i move to the next ten records the sort order is lost.

Does anybod have any ides how i can prevent this from happening? please see my code below...

"SELECT * FROM dbo.products WHERE category_name='lcd tv' OR category_name='televisions' OR category_name='plasma tv'" & Request.Form("SortField")


<form action="delete2.asp" method="post">
  Sort by:
  <select name="SortField">
    <option>ORDER BY display_price ASC</option>
    <option>ORDER BY display_price DESC</option>
  </select>
  <input type="submit" name="SortButton" value="Select">

</form>


Thank you.....

Back to Top
WebWiz-Bruce View Drop Down
Admin Group
Admin Group
Avatar
Web Wiz Developer

Joined: 03 September 2001
Location: Bournemouth
Status: Offline
Points: 9844
Post Options Post Options   Thanks (0) Thanks(0)   Quote WebWiz-Bruce Quote  Post ReplyReply Direct Link To This Post Posted: 21 August 2008 at 12:14pm
If you use this code you are leaving yourself wide open to an SQL Injection. Many new virus seek out and attack sites that are vulnerble to SQL Injection and both delete tables and place macious code into database.

What would be better is to pass across a value like 1 for ASC and 2 for DESC  like:-

strSQL = "SELECT TOP 10 * FROM dbo.products WHERE category_name='lcd tv' OR category_name='televisions' OR category_name='plasma tv' ORDER BY display_price "

If Request.Form("SortField") = "1" Then
     strSQL = strSQL & " ASC;"
Else
      strSQL = strSQL & " DESC;"
End If

<form action="delete2.asp" method="post">
  Sort by:
  <select name="SortField">
    <option value=1>ORDER BY display_price ASC</option>
    <option vlaue=2>ORDER BY display_price DESC</option>
  </select>
  <input type="submit" name="SortButton" value="Select">

</form>


Back to Top
shanerobinson View Drop Down
Newbie
Newbie


Joined: 21 August 2008
Status: Offline
Points: 17
Post Options Post Options   Thanks (0) Thanks(0)   Quote shanerobinson Quote  Post ReplyReply Direct Link To This Post Posted: 21 August 2008 at 2:18pm
Thanks, bruce i will give that a try
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.