Results 1 to 2 of 2

Thread: displaying a table in php

  1. #1
    Join Date
    Jan 2014

    Unhappy displaying a table in php

    Hi guys,

    I am having serious problems sorting a table according to the users option. I already have a working php code to display the table, I just have problems with the code to display the table with options the user has selected.

    The user can select an option of either asc or desc order from a drop box and the column they want arranged in the specified way.

    I have been able to develop the following code and keep getting an error message.Below is the code I generated n the error:
    if (isset($_POST['submitted']))

    $walkIn = $_POST['WalkIn'];

    $walkOut = $_POST['WalkOut'];

    $result = mysql_query("SELECT * FROM Results ORDER BY $walkIn $walkOut ")
    or die(mysql_error());


    the html


    Display table in =
    <select name="WalkIn">
    <option value="Please Choose">Please Choose</option>
    <option value="asc">Ascending order</option>
    <option value="desc">Descending order</option>


    on =
    <select name="WalkOut">
    <option value="Please Choose">Please Choose</option>
    <option value="Goliath">Goliath</option>
    <option value="Samson">Samson</option>


    would appreciate a guide in the right direction

  2. #2
    Join Date
    Aug 2004
    Looks like you need to invert the order of $walkIn and $walkOut in your query definition. Right now it would end up being something like:
    ... ORDER BY DESC goliath
    But it should be:
    ... ORDER BY goliath DESC
    PS: As currently coded, you are susceptible to SQL injection attacks/errors, since you do not sanitize those inputs. Also, if a (malicious) user sends some value for those 2 input parameters that is invalid (not a valid column name, or not "desc" or "asc"), your die() statement will spew information you may not want (malicious) users to see.
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center