PHP/MSSQL - Filtering from User Input (HTML)

后端 未结 3 749
离开以前
离开以前 2021-01-27 10:10

I have been given this assignment, to include some sort of filtering to my current SQL query via User Input. Basically, i am looking for a filtering option, whether its some kin

相关标签:
3条回答
  • 2021-01-27 10:47

    there should not be ANY data from user in sql query

    that did not pass filter

    sql-injection is not an empty word

    so no $_GET['week'] in sql if you didn't clear it

    0 讨论(0)
  • 2021-01-27 10:55

    i m not sure but maybe you can try.

    <input type="text" name="week"/>
    

    Post this textbox value in select page and set that value in where close.

    0 讨论(0)
  • 2021-01-27 10:59
     You can do that simply by introducing if else statement
     $where  = "";
     //receive filter option  example $_GET['week']  
      //Do some sanitizing for $_GET['week']
      if ($_GET['week']) {
      $where  =  "WHERE Test_Database.Week = $_GET['week']"
     } else if (somecondition) {
      $where  = "some query";
      }
    

    //You can add multiple condition by concatenating $where, but make sure where not repeats

    $query = "SELECT TOP 10 Test_Database.Distributor, Test_Database.Value
    FROM Test_Database
    $where  
    GROUP BY Distributor
    ORDER BY Value desc "
    
    0 讨论(0)
提交回复
热议问题