{"id":160,"date":"2009-07-30T12:46:57","date_gmt":"2009-07-30T17:46:57","guid":{"rendered":"http:\/\/abrammorphew.com\/notes\/?p=160"},"modified":"2009-07-30T12:49:08","modified_gmt":"2009-07-30T17:49:08","slug":"php-locator-script","status":"publish","type":"post","link":"http:\/\/abrammorphew.com\/notes\/2009\/07\/30\/php-locator-script\/","title":{"rendered":"PHP: Locator script"},"content":{"rendered":"<p>When asked to write a store location program in less than an hour, I developed this little utility. It uses my own MySQL class and clean() function which parses the POST\/GET variables for any nastiness that might have occurred. <\/p>\n<pre class=\"brush:php\">\r\ninclude('includes\/class.mysql.php');\r\ninclude('includes\/functions.php');\r\n\r\nclean(); \/\/ Clean up $_REQUEST for SQL injection\r\n$mysql = new mysql();\r\n$zip = $_REQUEST[zip];\r\n$city = $_REQUEST[city];\r\n$digits = strlen($zip);\r\n\/\/echo \"Count: $digits<br \/>\";\r\n\r\necho \"<?xml version=\\\"1.0\\\"?>\\n<xml>\\n\";\r\necho \"<storelist>\\n\";\r\nwhile($i<1) {\r\n        $q = ($zip) ? $mysql->query(\"SELECT * FROM stores WHERE zip LIKE '$zip%'\") : $mysql->query(\"SELECT * FROM stores WHERE state = '$_REQUEST[state]' AND city LIKE '%$city%' ORDER BY zip ASC\");\r\n        if(mysql_num_rows($q)) {\r\n                while($r = mysql_fetch_assoc($q)) {\r\n                        echo \"\\t<item>\\n\";\r\n                        echo \"\\t\\t<chain>\".trim($r[chain]).\"<\/chain>\\n\";\r\n                        echo \"\\t\\t<store>\".trim($r[store]).\"<\/store>\\n\";\r\n                        echo \"\\t\\t<location>\".trim($r[location]).\"<\/location>\\n\";\r\n                        echo \"\\t\\t<city>\".trim($r[city]).\"<\/city>\\n\";\r\n                        echo \"\\t\\t<state>\".trim($r[state]).\"<\/state>\\n\";\r\n                        echo \"\\t\\t<zip>\".trim($r[zip]).\"<\/zip>\\n\";\r\n                        echo \"\\t<\/item>\\n\";\r\n                }\r\n                $i++;\r\n        } else if (strlen($zip) > 1) {\r\n                $zip = substr($zip, 0, strlen($zip) - 1);\r\n        } else {\r\n                $i = 1;\r\n        }\r\n}\r\necho \"<\/storelist>\\n\";\r\necho \"<\/xml>\\n\";\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>When asked to write a store location program in less than an hour, I developed this little utility. It uses my own MySQL class and clean() function which parses the POST\/GET variables for any nastiness that might have occurred. include(&#8216;includes\/class.mysql.php&#8217;); include(&#8216;includes\/functions.php&#8217;); clean(); \/\/ Clean up $_REQUEST for SQL injection $mysql = new mysql(); $zip = [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[40,41,29,42],"class_list":["post-160","post","type-post","status-publish","format-standard","hentry","category-notes","tag-locator","tag-mysql","tag-php","tag-substr"],"_links":{"self":[{"href":"http:\/\/abrammorphew.com\/notes\/wp-json\/wp\/v2\/posts\/160","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/abrammorphew.com\/notes\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/abrammorphew.com\/notes\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/abrammorphew.com\/notes\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/abrammorphew.com\/notes\/wp-json\/wp\/v2\/comments?post=160"}],"version-history":[{"count":3,"href":"http:\/\/abrammorphew.com\/notes\/wp-json\/wp\/v2\/posts\/160\/revisions"}],"predecessor-version":[{"id":162,"href":"http:\/\/abrammorphew.com\/notes\/wp-json\/wp\/v2\/posts\/160\/revisions\/162"}],"wp:attachment":[{"href":"http:\/\/abrammorphew.com\/notes\/wp-json\/wp\/v2\/media?parent=160"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/abrammorphew.com\/notes\/wp-json\/wp\/v2\/categories?post=160"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/abrammorphew.com\/notes\/wp-json\/wp\/v2\/tags?post=160"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}