{"id":3076,"date":"2013-03-08T16:29:49","date_gmt":"2013-03-08T21:29:49","guid":{"rendered":"http:\/\/www.thejuliagroup.com\/blog\/?p=3076"},"modified":"2013-03-08T16:29:49","modified_gmt":"2013-03-08T21:29:49","slug":"the-hardest-errors-to-find-are-the-things-that-arent-there-a-php-example","status":"publish","type":"post","link":"https:\/\/www.thejuliagroup.com\/blog\/the-hardest-errors-to-find-are-the-things-that-arent-there-a-php-example\/","title":{"rendered":"The hardest errors to find are the things that aren&#8217;t there: A PHP example"},"content":{"rendered":"<p><em>In my defense, the actual program is longer than this &#8230;<\/em><\/p>\n<p>&lt;?php<br \/>\nrequire &#8216;connect.php&#8217;;<\/p>\n<p>\/\/ Create variables ;<br \/>\n$id = strtoupper(trim($_REQUEST[&#8216;id&#8217;])) ;<br \/>\n$application_date = $_REQUEST[&#8216;yr_of_apply&#8217;] . &#8220;-&#8221; . $_REQUEST[&#8216;month_of_apply&#8217;] .&#8221;-&#8220;. $_REQUEST[&#8216;day_of_apply&#8217;] ;<br \/>\n$assessment_date = $_REQUEST[&#8216;yr_of_assess&#8217;]. &#8220;-&#8221; . $_REQUEST[&#8216;month_of_assess&#8217;] .&#8221;-&#8220;. $_REQUEST[&#8216;day_of_assess&#8217;] ;<br \/>\n$eligibility_date = $_REQUEST[&#8216;yr_eligible&#8217;].&#8221;-&#8220;.$_REQUEST[&#8216;month_eligible&#8217;] .&#8221;-&#8220;. $_REQUEST[&#8216;day_eligible&#8217;] ;<br \/>\n$ipe_date = $_REQUEST[&#8216;yr_ipe&#8217;].&#8221;-&#8220;.$_REQUEST[&#8216;month_ipe&#8217;] .&#8221;-&#8220;. $_REQUEST[&#8216;day_ipe&#8217;] ;<\/p>\n<p>$notify_rights = $_REQUEST[&#8216;notify_rights&#8217;] ;<br \/>\n$vocational_goal = $_REQUEST[&#8216;vocational_goal&#8217;] ;<\/p>\n<p>\/\/ Get user info ;<\/p>\n<p>$result = mysql_query(&#8220;UPDATE clients SET notify_rights = &#8216;$notify_rights&#8217;, vocational_goal = &#8216;$vocational_goal&#8217; ,<br \/>\napplication_date = &#8216;$application_date&#8217; , assessment_date = &#8216;$assessment_date&#8217;<br \/>\nWHERE id = &#8216;$id'&#8221;)<br \/>\nor die(mysql_error()) ;<br \/>\necho &#8220;&lt;p&gt;Your record was updated successfully.&lt;\/p&gt;&#8221; ;<br \/>\n?&gt;<\/p>\n<p>So, it didn&#8217;t work. All I wanted to do was connect to the SQL database, find the client&#8217;s id and update that record with the application information.<\/p>\n<p>First problem I found was that I had tested this with a much smaller file with just a few columns and in my UPDATE statement it still had the table &#8216;test&#8217; instead of &#8216;clients&#8217;. I was getting an error that said there was &#8220;an error in my SQL code&#8221;. Which is true. Since the table did exist, I wasn&#8217;t getting an error saying it wasn&#8217;t found. Ok, I fixed that<\/p>\n<p>Second problem, the dates were actually entered in three different fields to make it easier for error checking &#8211; your year has to be within the current fiscal year, month between 1 and 12, no entering April 31. However, I needed those to BE dates for analyses we plan later. So, I just created the date variables. Problem solved.<\/p>\n<p>Third problem, I realized I really did not want the password and other information required for connection in this program where anyone could see it. There is no personally identifiable information in here, but it&#8217;s just a bad habit to have your passwords and other data hanging out there. Hence the statement to require the connect.php script .<\/p>\n<p>Fourth problem, the ID variable is not a number. It can be something like ABJ-001 , so it doesn&#8217;t match if it the case is not the same or if there are spaces. The strtoupper and trim functions fixed that.<\/p>\n<p>Fifth problem, some of the dates were blank. I looked at them over and over to see if I had mismatched quotes . I even actually deleted and re-typed the statements. Nope, still, some of the dates were there and others were blank. Maybe they weren&#8217;t date format in the table definition? Nope, I checked and the missing dates and the dates that updated properly were all defined as the same format.<\/p>\n<p>Well, maybe you spotted it already &#8230; As I said in the first problem, I had originally created and tested the script with a table named &#8216;test&#8217; that had just a few columns. When I switched to my client table, I had forgotten to add all of the columns to the UPDATE statement. The problem wasn&#8217;t in creating the eligibility and ipe date fields. The problem was that I left those fields off of the update statement so they were never getting updated. Everything went through fine, I got a message saying my record was updated &#8211; because as far as PHP was concerned, it wasn&#8217;t an error. Maybe I only wanted to update some of the columns.<\/p>\n<p>The moral of the story is this: Sometimes the problem is the code you DIDN&#8217;T write.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In my defense, the actual program is longer than this &#8230; &lt;?php require &#8216;connect.php&#8217;; \/\/ Create variables ; $id = strtoupper(trim($_REQUEST[&#8216;id&#8217;])) ; $application_date = $_REQUEST[&#8216;yr_of_apply&#8217;] . &#8220;-&#8221; . $_REQUEST[&#8216;month_of_apply&#8217;] .&#8221;-&#8220;. $_REQUEST[&#8216;day_of_apply&#8217;] ; $assessment_date = $_REQUEST[&#8216;yr_of_assess&#8217;]. &#8220;-&#8221; . $_REQUEST[&#8216;month_of_assess&#8217;] .&#8221;-&#8220;. $_REQUEST[&#8216;day_of_assess&#8217;] ; $eligibility_date = $_REQUEST[&#8216;yr_eligible&#8217;].&#8221;-&#8220;.$_REQUEST[&#8216;month_eligible&#8217;] .&#8221;-&#8220;. $_REQUEST[&#8216;day_eligible&#8217;] ; $ipe_date = $_REQUEST[&#8216;yr_ipe&#8217;].&#8221;-&#8220;.$_REQUEST[&#8216;month_ipe&#8217;] .&#8221;-&#8220;. $_REQUEST[&#8216;day_ipe&#8217;] ; $notify_rights =&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[9],"tags":[],"class_list":["post-3076","post","type-post","status-publish","format-standard","hentry","category-software"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/posts\/3076","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/comments?post=3076"}],"version-history":[{"count":1,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/posts\/3076\/revisions"}],"predecessor-version":[{"id":3077,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/posts\/3076\/revisions\/3077"}],"wp:attachment":[{"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/media?parent=3076"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/categories?post=3076"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/tags?post=3076"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}