php文件不回显来自远程服务器上的mysql表的查询BUT适用于本地XAMMP mariaDB

SUMMARY:

  • I am new to back-end development.
  • For my site, the user inputs a city location and date then clicks on the submit button for a selection of activites to do.
  • City GPS coordinates are supplied by geobytes.com JSON-P API's
  • The date is supplied by jQuery datepicker
  • The coordinates and date are extracted within an external javascript file then passed to a PHP file (AJAX) for querying several tables, and then the results are echoed back to the webpage.
  • On my local machine using XAMMP, everything works.
  • On my student web space, a query on a table that uses both GPS and date DOES NOT echo

BACKGROUND:

  • The PHP code is the same on both servers, except for connection
  • Queries of locations tables work
  • Queries of dates tables work
  • One table has fields containing both GPS and date. This query does NOT echo from the school server.
  • Local machine is MariaDB 10.1.38 // XAMMP v3.2.3 on windows 10)
  • School mysql server version is 5.5.54 (on unix)
  • PHP Version 7.3.3
// PHP code
// AJAX VALUES PASSED FROM JAVASCRIPT FILE`
$s = $_GET['s'];
$q = floatval($_GET['q']);
$r = floatval($_GET['r']);

// FOR MYSQL
$sqlStarParty = "SELECT sp_name, sp_location, sp_date_start, sp_nights, sp_link, sp_comment
FROM star_party 
WHERE 
sp_date_start <= DATE_ADD(STR_TO_DATE('$s', '%Y-%m-%d'), INTERVAL 14 DAY)
AND
sp_date_start >= DATE_SUB(STR_TO_DATE('$s', '%Y-%m-%d'), INTERVAL 14 DAY)
AND
sp_latitude < ($q + 2) AND sp_latitude > ($q - 2)
AND
sp_longitude < ($r + 2) AND sp_longitude > ($r - 2)";


// TO BE ECHOED TO WEBPAGE
$resultStarParty = mysqli_query($conn, $sqlStarParty);

if (mysqli_num_rows($resultStarParty) > 0) {

while($row = mysqli_fetch_assoc($resultStarParty)) {
    echo $row["sp_name"] . "<br/>";
    echo "Location : " . $row["sp_location"] . "<br/>";
    echo "Current year event start date: " . date_format(new DateTime($row["sp_date_start"]),'F, jS') . " for " . $row["sp_nights"] . " nights<br/>"; 
        echo "Details and map: " . "<a href='".$row["sp_link"]."' target='_blank'>Website</a><br/>";
        echo "<br></br>";
    }
}   // if no records match query - print 0 results
 else {
     echo "Sorry no star parties for this time and location";
}

EXPECTED RESULTS:

  • All queries dates/location/date + location should echo to webpage. ACTUAL RESULTS:
  • A user submits a location and date which lands on a star party event date range (+- 14 days)
  • No error messages show
  • No response from submit button OR no echo of star party table.
  • Any help would be much appreciated!

SOLUTION:

  • I was getting a 500 server error, which could be many things.
  • The MySQL DB was getting the correct js variable values.
  • Problem was rectified when saw that the two tables giving me grief were using NEW DATE_TIME.
  • Change PHP code to date_create instead. Star party results are showing and correct.
  • Thank you Paulo!

I think I've solved it. Where date_format(new DateTime($row["op_date"]) occured, I replaced with date_format(date_create($row["op_date"]). Star Parties are showing correctly now. Hopefully this holds.