Ajax从MySQL提取数据

I'm currently trying to set up an easy temperature monitoring system for our lab. It's controlled through a web interface which plots the temperature vs. time data in a Dygraph. The temperature data is written into a mySQL DB. I'm trying to add another input field which can be used to select a certain time range to plot. I'm currently using a jQuery datebox to select the time window which seems to work fine. I'm sending an AJAX request to a PHP script which queries the DB. Instead of showing me the right data points, the PHP script just outputs an internal server error (500). The script works fine when the $_POST section of the PHP and the data part of the jQuery script is deleted.

My most recent JS code is:

$("#UpdateGraph").on("click", function(){
    var startDate = $("#datestart").val();
    var endDate = $("#datestop").val();
    $.ajax({
    url: "updateGraph.php",
    data: {start : startDate,
           stop : endDate},
    datatype: "json",
    type: "POST",
    success: function(data) { DyGraph(data); }
    });
});

The jQuery code is housed in a $(document).ready() environment. The corresponding PHP script looks like this:

  <?php
 $conn = new PDO("mysql:host=localhost;dbname=temperature", "USERNAME", "PASSWORD");
 $results = array();

 $startDate = $_POST['start'];
 $stopDate = $_POST['stop']: 

 $query = "SELECT atime,temperature FROM temp WHERE atime BETWEEN '"  . $startDate . "' AND '"  . $stopDate . "';" ;
 $stmt = $conn->prepare($query);
 $stmt->execute();
 while($result = $stmt->fetch(PDO::FETCH_ASSOC)){
  $results[] = $result['atime'].",".$result['temperature'];
 }
 print_r(json_encode(implode("
+",$results)));
?>

Any advice what I'm doing wrong? Thanks a lot!

I guess, the source of your error is a syntax error in line $stopDate = $_POST['stop']: There is a colon at the end of the line. You should change it to semicolon.

Syntax errors in php scripts at the server will show error 500 in http clients. I suggest you to use a linter to avoid this kind of errors. All the popular editors have plugins for this.