{"id":1736,"date":"2017-03-21T23:47:25","date_gmt":"2017-03-22T04:47:25","guid":{"rendered":"https:\/\/rpchurchill.com\/wordpress\/?p=1736"},"modified":"2017-03-24T00:51:43","modified_gmt":"2017-03-24T05:51:43","slug":"to-do-list-project-part-5","status":"publish","type":"post","link":"https:\/\/rpchurchill.com\/wordpress\/posts\/2017\/03\/21\/to-do-list-project-part-5\/","title":{"rendered":"To Do List Project: Part 5"},"content":{"rendered":"<p>The next step is to make the back end actually write some data to a database using PHP and MySQL.  This is the UpdateStartTime.php file.  The startSliceAjax function that communicates with this PHP is shown below, just slightly modified from yesterday&#8217;s version.<\/p>\n<p>The PHP simply inserts the sent information into the database.  Each <code>ToDoSlice<\/code> item has an index indicating the unique ID of the To Do item with which it is associated but not a unique ID of its own.  When writing the start time of a new slice this isn&#8217;t a problem because the slice item is being created anew and doesn&#8217;t have to match anything.<\/p>\n<pre class=\"toolbar-overlay:false wrap:false height-set:true lang:default decode:true \">\r\n<?php\r\n  include('SQLFunctions.php');\r\n\r\n  if (!empty($_GET)) {\r\n    $tdRecordToDoID = $_GET['ToDoIDx'];\r\n    $tdNote = $_GET['Notex'];\r\n    $tdStartTime = date('Y-m-d H:i:s', time());\r\n    \r\n    $link = connectDB();\r\n  \r\n    $sql = \"insert into ToDoSlices (recordToDoID, startTime, Note) values\r\n    (\".$tdRecordToDoID.\",'\".$tdStartTime.\"','\".$tdNote.\"');\";\r\n\r\n    if (mysqli_query($link, $sql)) {\r\n      echo $tdStartTime;\r\n    } else {\r\n      echo \"Error: \".$sql.\"<br>\".mysqli_error($link);\r\n    }\r\n    \r\n    mysqli_close( $link );\r\n  }\r\n?>\r\n<\/pre>\n<pre class=\"toolbar-overlay:false wrap:false height-set:true lang:default decode:true \">\r\n      echo \"    function startSliceAjax() {\";\r\n      echo \"      var xmlhttp = new XMLHttpRequest();\";\r\n      echo \"      var handle = document.getElementById('startButton');\";\r\n      echo \"      var parentHandle = handle.parentNode;\";\r\n      echo \"      xmlhttp.onreadystatechange = function() {\";\r\n      echo \"        if (this.readyState == 4) {\";\r\n      echo \"          if (this.status == 200) {\";\r\n      echo \"            if (this.responseText.search('Error: ') < 0) {\";\r\n      echo \"              parentHandle.innerHTML = this.responseText;\";\r\n      echo \"              startSliceTime = new Date(this.responseText);\";\r\n      echo \"              parentHandle.nextElementSibling.innerHTML = `<button type='button' id='endButton' onmouseup='endSliceAjax()'>End<\/button>`;\";\r\n      echo \"              sliceIndex = parentHandle.previousElementSibling.innerHTML;\";\r\n      echo \"            } else {\";\r\n      echo \"              alert(this.responseText);\";\r\n      echo \"            }\";\r\n      echo \"          } else {\";\r\n      echo \"            alert('AJAX error encountered');\";\r\n      echo \"          }\";\r\n      echo \"        }\";\r\n      echo \"      };\";\r\n      echo \"      var noteHandle = document.getElementById('nextSliceNoteID');\";\r\n      echo \"      var noteValue = noteHandle.value;\";\r\n      echo \"      xmlhttp.open('GET','UpdateStartTime.php?ToDoIDx='+$ToDoID+'&Notex='+noteValue, true);\";\r\n      echo \"      xmlhttp.send();\";\r\n      echo \"    }\";\r\n<\/pre>\n<p>We&#8217;re receiving the echoed text from the PHP and displaying it based on what data it contains.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The next step is to make the back end actually write some data to a database using PHP and MySQL. This is the UpdateStartTime.php file. The startSliceAjax function that communicates with this PHP is shown below, just slightly modified from &hellip; <a href=\"https:\/\/rpchurchill.com\/wordpress\/posts\/2017\/03\/21\/to-do-list-project-part-5\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[169,49,82,165,167],"_links":{"self":[{"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/posts\/1736"}],"collection":[{"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/comments?post=1736"}],"version-history":[{"count":1,"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/posts\/1736\/revisions"}],"predecessor-version":[{"id":1737,"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/posts\/1736\/revisions\/1737"}],"wp:attachment":[{"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/media?parent=1736"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/categories?post=1736"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/tags?post=1736"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}