Advertisement
Guest User

PHP

a guest
Aug 20th, 2014
371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 12.30 KB | None | 0 0
  1. <?php
  2. $whereClause = array();
  3. $bindArray = array();
  4.  
  5. $county1 = filter_input(INPUT_POST, 'county1', FILTER_SANITIZE_STRING);
  6. $county2 = filter_input(INPUT_POST, 'county2', FILTER_SANITIZE_STRING);
  7. $county3 = filter_input(INPUT_POST, 'county3', FILTER_SANITIZE_STRING);
  8. $county4 = filter_input(INPUT_POST, 'county4', FILTER_SANITIZE_STRING);
  9. $county5 = filter_input(INPUT_POST, 'county5', FILTER_SANITIZE_STRING);
  10. $county6 = filter_input(INPUT_POST, 'county6', FILTER_SANITIZE_STRING);
  11. $bhv = filter_input(INPUT_POST, 'bhv', FILTER_SANITIZE_STRING);
  12. $mrc = filter_input(INPUT_POST, 'mrc', FILTER_SANITIZE_STRING);
  13. $general = filter_input(INPUT_POST, 'general', FILTER_SANITIZE_STRING);
  14. $evv = filter_input(INPUT_POST, 'evv', FILTER_SANITIZE_STRING);
  15. $allCounties = filter_input(INPUT_POST, 'allCounties', FILTER_SANITIZE_STRING);
  16. $fillmore = filter_input(INPUT_POST, 'fillmore', FILTER_SANITIZE_STRING);
  17. $johnson = filter_input(INPUT_POST, 'johnson', FILTER_SANITIZE_STRING);
  18. $otoe = filter_input(INPUT_POST, 'otoe', FILTER_SANITIZE_STRING);
  19. $richardson = filter_input(INPUT_POST, 'richardson', FILTER_SANITIZE_STRING);
  20. $seward = filter_input(INPUT_POST, 'seward', FILTER_SANITIZE_STRING);
  21. $butler = filter_input(INPUT_POST, 'butler', FILTER_SANITIZE_STRING);
  22. $gage = filter_input(INPUT_POST, 'gage', FILTER_SANITIZE_STRING);
  23. $lancaster = filter_input(INPUT_POST, 'lancaster', FILTER_SANITIZE_STRING);
  24. $pawnee = filter_input(INPUT_POST, 'pawnee', FILTER_SANITIZE_STRING);
  25. $saline = filter_input(INPUT_POST, 'saline', FILTER_SANITIZE_STRING);
  26. $thayer = filter_input(INPUT_POST, 'thayer', FILTER_SANITIZE_STRING);
  27. $cass = filter_input(INPUT_POST, 'cass', FILTER_SANITIZE_STRING);
  28. $jefferson = filter_input(INPUT_POST, 'jefferspm', FILTER_SANITIZE_STRING);
  29. $nemaha = filter_input(INPUT_POST, 'nemaha', FILTER_SANITIZE_STRING);
  30. $polk = filter_input(INPUT_POST, 'polk', FILTER_SANITIZE_STRING);
  31. $saunders = filter_input(INPUT_POST, 'saunders', FILTER_SANITIZE_STRING);
  32. $york = filter_input(INPUT_POST, 'york', FILTER_SANITIZE_STRING);
  33. $aro = filter_input(INPUT_POST, 'aro', FILTER_SANITIZE_STRING);
  34. $clergy = filter_input(INPUT_POST, 'clergy', FILTER_SANITIZE_STRING);
  35. $intskills = filter_input(INPUT_POST, 'intskills', FILTER_SANITIZE_STRING);
  36. $bus = filter_input(INPUT_POST, 'bus', FILTER_SANITIZE_STRING);
  37. $child = filter_input(INPUT_POST, 'child', FILTER_SANITIZE_STRING);
  38. $law = filter_input(INPUT_POST, 'law', FILTER_SANITIZE_STRING);
  39. $cpr = filter_input(INPUT_POST, 'cpr', FILTER_SANITIZE_STRING);
  40. $data = filter_input(INPUT_POST, 'data', FILTER_SANITIZE_STRING);
  41. $security = filter_input(INPUT_POST, 'security', FILTER_SANITIZE_STRING);
  42. $emergency = filter_input(INPUT_POST, 'emergency', FILTER_SANITIZE_STRING);
  43. $computer = filter_input(INPUT_POST, 'computer', FILTER_SANITIZE_STRING);
  44. $mechanical = filter_input(INPUT_POST, 'mechanical', FILTER_SANITIZE_STRING);
  45. $administration = filter_input(INPUT_POST, 'administration', FILTER_SANITIZE_STRING);
  46. $firstaid = filter_input(INPUT_POST, 'firstaid', FILTER_SANITIZE_STRING);
  47. $translation = filter_input(INPUT_POST, 'translation', FILTER_SANITIZE_STRING);
  48. $construction = filter_input(INPUT_POST, 'construction', FILTER_SANITIZE_STRING);
  49. $basicclean = filter_input(INPUT_POST, 'basicclean', FILTER_SANITIZE_STRING);
  50. $foodprep = filter_input(INPUT_POST, 'foodprep', FILTER_SANITIZE_STRING);
  51. $animalcare = filter_input(INPUT_POST, 'animalcare', FILTER_SANITIZE_STRING);
  52. $heavy = filter_input(INPUT_POST, 'heavy', FILTER_SANITIZE_STRING);
  53. $license1 = filter_input(INPUT_POST, 'license1', FILTER_SANITIZE_STRING);
  54. $license2 = filter_input(INPUT_POST, 'license2', FILTER_SANITIZE_STRING);
  55. $license3 = filter_input(INPUT_POST, 'license3', FILTER_SANITIZE_STRING);
  56. $license4 = filter_input(INPUT_POST, 'license4', FILTER_SANITIZE_STRING);
  57. $license5 = filter_input(INPUT_POST, 'license5', FILTER_SANITIZE_STRING);
  58. $dist1 = filter_input(INPUT_POST, 'dist1', FILTER_SANITIZE_STRING);
  59. $dist2 = filter_input(INPUT_POST, 'dist2', FILTER_SANITIZE_STRING);
  60. $dist3 = filter_input(INPUT_POST, 'dist3', FILTER_SANITIZE_STRING);
  61. $dist4 = filter_input(INPUT_POST, 'dist4', FILTER_SANITIZE_STRING);
  62. $dist5 = filter_input(INPUT_POST, 'dist5', FILTER_SANITIZE_STRING);
  63.  
  64. if(!empty($bhv)){
  65.     $whereClause[] = '`bhv` = :bhv';
  66.     $bindArray[':bhv'] = $bhv;
  67. } else {
  68.     $bhv = "";
  69. }
  70. if(!empty($mrc)){
  71.     $whereClause[] = '`mrc` = :mrc';
  72.     $bindArray[':mrc'] = $mrc;
  73. } else {
  74.     $mrc = "";
  75. }
  76. if(!empty($general)){
  77.     $whereClause[] = '`general` = :general';
  78.     $bindArray[':general'] = $general;
  79. } else {
  80.     $general = "";
  81. }
  82. if(!empty($evv)){
  83.     $whereClause[] = '`evv` = :evv';
  84.     $bindArray[':evv'] = $evv;
  85. } else {
  86.     $evv = "";
  87. }
  88. if(!empty($allCounties)){
  89.     $whereClause[] = '`allCounties` = :allCounties';
  90.     $bindArray[':allCounties'] = $allCounties;
  91. } else {
  92.     $allCounties = "";
  93. }
  94. if(!empty($fillmore)){
  95.     $whereClause[] = '`fillmore` = :fillmore';
  96.     $bindArray[':fillmore'] = $fillmore;
  97. } else {
  98.     $fillmore = "";
  99. }
  100. if(!empty($johnson)){
  101.     $whereClause[] = '`johnson` = :johnson';
  102.     $bindArray[':johnson'] = $johnson;
  103. } else {
  104.     $johnson = "";
  105. }
  106. if(!empty($otoe)){
  107.     $whereClause[] = '`otoe` = :otoe';
  108.     $bindArray[':otoe'] = $otoe;
  109. } else {
  110.     $otoe = "";
  111. }
  112. if(!empty($richardson)){
  113.     $whereClause[] = '`richardson` = :richardson';
  114.     $bindArray[':richardson'] = $richardson;
  115. } else {
  116.     $richardson = "";
  117. }
  118. if(!empty($seward)){
  119.     $whereClause[] = '`seward` = :seward';
  120.     $bindArray[':seward'] = $seward;
  121. } else {
  122.     $seward = "";
  123. }
  124. if(!empty($butler)){
  125.     $whereClause[] = '`butler` = :butler';
  126.     $bindArray[':butler'] = $butler;
  127. } else {
  128.     $butlet = "";
  129. }
  130. if(!empty($gage)){
  131.     $whereClause[] = '`gage` = :gage';
  132.     $bindArray[':gage'] = $gage;
  133. } else {
  134.     $gage = "";
  135. }
  136. if(!empty($lancaster)){
  137.     $whereClause[] = '`lancaster` = :lancaster';
  138.     $bindArray[':lancaster'] = $lancaster;
  139. } else {
  140.     $lancaster = "";
  141. }
  142. if(!empty($pawnee)){
  143.     $whereClause[] = '`pawnee` = :pawnee';
  144.     $bindArray[':pawnee'] = $pawnee;
  145. } else {
  146.     $pawnee = "";
  147. }
  148. if(!empty($saline)){
  149.     $whereClause[] = '`saline` = :saline';
  150.     $bindArray[':saline'] = $saline;
  151. } else {
  152.     $saline = "";
  153. }
  154. if(!empty($thayer)){
  155.     $whereClause[] = '`thayer` = :thayer';
  156.     $bindArray[':thayer'] = $thayer;
  157. } else {
  158.     $thayer = "";
  159. }
  160. if(!empty($cass)){
  161.     $whereClause[] = '`cass` = :cass';
  162.     $bindArray[':cass'] = $cass;
  163. } else {
  164.     $cass = "";
  165. }
  166. if(!empty($jefferson)){
  167.     $whereClause[] = '`jefferson` = :jefferson';
  168.     $bindArray[':jefferson'] = $jefferson;
  169. } else {
  170.     $jefferson = "";
  171. }
  172. if(!empty($nemaha)){
  173.     $whereClause[] = '`nemaha` = :nemaha';
  174.     $bindArray[':nemaha'] = $nemaha;
  175. } else {
  176.     $nemaha = "";
  177. }
  178. if(!empty($polk)){
  179.     $whereClause[] = '`polk` = :polk';
  180.     $bindArray[':polk'] = $polk;
  181. } else {
  182.     $polk = "";
  183. }
  184. if(!empty($saunders)){
  185.     $whereClause[] = '`saunders` = :saunders';
  186.     $bindArray[':saunders'] = $saunders;
  187. } else {
  188.     $saunders = "";
  189. }
  190. if(!empty($york)){
  191.     $whereClause[] = '`york` = :york';
  192.     $bindArray[':york'] = $york;
  193. } else {
  194.     $york = "";
  195. }
  196. if(!empty($aro)){
  197.     $whereClause[] = '`aro` = :aro';
  198.     $bindArray[':aro'] = $aro;
  199. } else {
  200.     $aro = "";
  201. }
  202. if(!empty($clergy)){
  203.     $whereClause[] = '`clergy` = :clergy';
  204.     $bindArray[':clergy'] = $clergy;
  205. } else {
  206.     $clergy = "";
  207. }
  208. if(!empty($intskills)){
  209.     $whereClause[] = '`intskills` = :intskills';
  210.     $bindArray[':intskills'] = $intskills;
  211. } else {
  212.     $intskills = "";
  213. }
  214. if(!empty($child)){
  215.     $whereClause[] = '`child` = :child';
  216.     $bindArray[':child'] = $child;
  217. } else {
  218.     $child = "";
  219. }
  220. if(!empty($bus)){
  221.     $whereClause[] = '`bus` = :bus';
  222.     $bindArray[':bus'] = $bus;
  223. } else {
  224.     $bus = "";
  225. }
  226. if(!empty($law)){
  227.     $whereClause[] = '`law` = :law';
  228.     $bindArray[':law'] = $law;
  229. } else {
  230.     $law = "";
  231. }
  232. if(!empty($cpr)){
  233.     $whereClause[] = '`cpr` = :cpr';
  234.     $bindArray[':cpr'] = $cpr;
  235. } else {
  236.     $cpr = "";
  237. }
  238. if(!empty($data)){
  239.     $whereClause[] = '`data` = :data';
  240.     $bindArray[':data'] = $data;
  241. } else {
  242.     $data = "";
  243. }
  244. if(!empty($security)){
  245.     $whereClause[] = '`security` = :security';
  246.     $bindArray[':security'] = $security;
  247. } else {
  248.     $security = "";
  249. }
  250. if(!empty($emergency)){
  251.     $whereClause[] = '`emergency` = :emergency';
  252.     $bindArray[':emergency'] = $emergency;
  253. } else {
  254.     $emergency = "";
  255. }
  256. if(!empty($computer)){
  257.     $whereClause[] = '`computer` = :computer';
  258.     $bindArray[':computer'] = $computer;
  259. } else {
  260.     $computer = "";
  261. }if(!empty($mechanical)){
  262.     $whereClause[] = '`machanical` = :machanical';
  263.     $bindArray[':machanical'] = $machanical;
  264. } else {
  265.     $machanical = "";
  266. }
  267. if(!empty($administration)){
  268.     $whereClause[] = '`administration` = :administration';
  269.     $bindArray[':administration'] = $administration;
  270. } else {
  271.     $administration = "";
  272. }
  273. if(!empty($firstaid)){
  274.     $whereClause[] = '`firstaid` = :firstaid';
  275.     $bindArray[':firstaid'] = $firstaid;
  276. } else {
  277.     $firstaid = "";
  278. }
  279. if(!empty($translation)){
  280.     $whereClause[] = '`translation` = :translation';
  281.     $bindArray[':translation'] = $translation;
  282. } else {
  283.     $translation = "";
  284. }
  285. if(!empty($construction)){
  286.     $whereClause[] = '`construction` = :construction';
  287.     $bindArray[':construction'] = $construction;
  288. } else {
  289.     $construction = "";
  290. }
  291. if(!empty($basicclean)){
  292.     $whereClause[] = '`basicclean` = :basicclean';
  293.     $bindArray[':basicclean'] = $basicclean;
  294. } else {
  295.     $basicclean = "";
  296. }
  297. if(!empty($foodprep)){
  298.     $whereClause[] = '`foodprep` = :foodprep';
  299.     $bindArray[':foodprep'] = $foodprep;
  300. } else {
  301.     $foodprep = "";
  302. }
  303. if(!empty($animalcare)){
  304.     $whereClause[] = '`animalcare` = :animalcare';
  305.     $bindArray[':animalcare'] = $animalcare;
  306. } else {
  307.     $animalcare = "";
  308. }
  309. if(!empty($heavy)){
  310.     $whereClause[] = '`heavy` = :heavy';
  311.     $bindArray[':heavy'] = $heavy;
  312. } else {
  313.     $heavy = "";
  314. }
  315. if ($county1 == ""){
  316.     $error = "Must select at least 1 Residential County.";
  317.     echo $error;
  318. } elseif ($count2 == ""){
  319.     $whereClause[] = '`county` = :county1';
  320. } elseif ($county3 == "") {
  321.     $whereClause[] = '`county` = :county1  OR `county` = :county2';
  322. } elseif ($county4 == ""){
  323.     $whereClause[] = '`county` = :county1  OR `county` = :county2 OR `county` = :county3';
  324. } elseif ($county5 == ""){
  325.     $whereClause[] = '`county` = :county1  OR `county` = :county2 OR `county` = :county3 OR `county` = :county4';
  326. } elseif ($county6 == ""){
  327.     $whereClause[] = '`county` = :county1  OR `county` = :county2 OR `county` = :county3 OR `county` = :county OR `county` = :county5';
  328. } else {
  329.    $whereClause[] = '`county` = :county1  OR `county` = :county2 OR `county` = :county3 OR `county` = :county OR `county` = :county5 OR `county` = :county6';
  330. }
  331. if(!empty($license1)){
  332.     $whereClause[] = '`license1` = :license1';
  333.     $bindArray[':license1'] = $license1;
  334. }
  335. if(!empty($license2)){
  336.     $whereClause[] = '`license2` = :license2';
  337.     $bindArray[':license2'] = $license2;
  338. }
  339. if(!empty($license3)){
  340.     $whereClause[] = '`license3` = :license3';
  341.     $bindArray[':license3'] = $license3;
  342. }
  343. if(!empty($license4)){
  344.     $whereClause[] = '`license4` = :license4';
  345.     $bindArray[':license4'] = $license4;
  346. }
  347. if(!empty($license5)){
  348.     $whereClause[] = '`license5` = :license5';
  349.     $bindArray[':license5'] = $license5;
  350. }
  351. if(!empty($dis1)){
  352.     $whereClause[] = '`dist1` = :dist1';
  353.     $bindArray[':dist1'] = $dist1;
  354. }
  355. if(!empty($dist2)){
  356.     $whereClause[] = '`dist2` = :dist2';
  357.     $bindArray[':dist2'] = $dist2;
  358. }
  359. if(!empty($dist3)){
  360.     $whereClause[] = '`dist3` = :dist3';
  361.     $bindArray[':dist3'] = $dist3;
  362. }
  363. if(!empty($dist4)){
  364.     $whereClause[] = '`dist4` = :dist4';
  365.     $bindArray[':dist4'] = $dist4;
  366. }
  367. if(!empty($dist5)){
  368.     $whereClause[] = '`dist5` = :dist5';
  369.     $bindArray[':dist5'] = $dist5;
  370. }
  371. $dbh = new PDO('mysql:host=localhost;dbname=petrzilk_test;charset=utf8', 'petrzilk_dbAdmin', 'xxxxxxxxx');
  372. $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  373. $dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
  374. $stmtString = 'SELECT * FROM VolunDB';
  375. if(!empty($whereClause)) $stmtString .= ' WHERE ' . implode(' AND ', $whereClause);
  376. $stmt = $dbh->prepare($stmtString);
  377. $stmt->execute($bindArray);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement