title: PHP MySQL query from date variable
body: <p>I'm trying to query a table from my DB based on a date user input.
  This is my code:</p>
  
  <pre><code>&lt;input type="date" name="date" value="&lt;?php echo date('Y-m-d'); ?&gt;"&gt;
  &lt;input type="submit" value="&gt;" onclick="showDate(this.value)"&gt;
  </code></pre>
  
  <p>for the user input (its defaulted to the current date)</p>
  
  <p>and here is my php script</p>
  
  <pre><code>$q = $_GET['date'];
  
  $sql="SELECT * FROM mathtest WHERE testdate = '$q'";
  $result = mysqli_query($con,$sql);
  </code></pre>
  
  <p>this is my ajax script:</p>
  
  <pre><code>&lt;script&gt;
  function showDate(str) {
  if (str == "") {
  document.getElementById("mathtestHere").innerHTML = "";
  return;
  } else {
  if (window.XMLHttpRequest) {
      // code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp = new XMLHttpRequest();
  } else {
      // code for IE6, IE5
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.onreadystatechange = function() {
      if (this.readyState == 4 &amp;&amp; this.status == 200) {
          document.getElementById("mathtestHere").innerHTML = 
  this.responseText;
      }
  };
  xmlhttp.open("GET","getmathdate.php?q="+str,true);
  xmlhttp.send();
  }
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>and my php echo function:</p>
  
  <pre><code>echo "&lt;table&gt;
  &lt;tr&gt;
  &lt;th&gt;ID&lt;/th&gt;
  &lt;th&gt;First name&lt;/th&gt;
  &lt;th&gt;Last name&lt;/th&gt;
  &lt;th&gt;Level&lt;/th&gt;
  &lt;th&gt;Time&lt;/th&gt;
  &lt;th&gt;Score&lt;/th&gt;
  &lt;th&gt;Date&lt;/th&gt;
  &lt;th&gt;Added by&lt;/th&gt;
  &lt;/tr&gt;";
  while($row = mysqli_fetch_array($result)) {
  echo "&lt;tr&gt;";
  echo "&lt;td&gt;" . $row['id'] . "&lt;/td&gt;";
  echo "&lt;td&gt;" . $row['firstname'] . "&lt;/td&gt;";
  echo "&lt;td&gt;" . $row['lastname'] . "&lt;/td&gt;";
  echo "&lt;td&gt;" . $row['testlevel'] . "&lt;/td&gt;";
  echo "&lt;td&gt;" . $row['testtime'] . "&lt;/td&gt;";
  echo "&lt;td&gt;" . $row['testscore'] . "&lt;/td&gt;";
  echo "&lt;td&gt;" . $row['testdate'] . "&lt;/td&gt;";
  echo "&lt;td&gt;" . $row['addedBy'] . "&lt;/td&gt;";
  echo "&lt;/tr&gt;";
  }
  echo "&lt;/table&gt;";
  mysqli_close($con);
  </code></pre>
  
  <p>and then echo'd into a php table. I'm using an AJAX onclick function to render the tables into my body.</p>
  
  <p>For some reason, it won't show the tests that were taken on that date. 
  Thanks!</p>