Getting a blank screen with no errors and no code. I have php version 5.3.10 on my live server but the code was developed on a local computer with version 5.6.2. The code written below was written for latest version of PHP but the live server the page will sit on has the old version 5.3.10.
I need to know which PHP syntax below is new and needs to be backwards compatible.
// Triggered when the Export CSV button is clicked.
if(isset($_POST["search_results"]) && isset($_POST["pub_results"]) ) {
// Sets the value of the hidden field as a variable (the value will be the SQL query saved earlier)
$results = $_POST['search_results'];
$pubResults = $_POST['pub_results'];
$query = $pubResults;
// Performs the query again to get the results to export
$r = mysqli_query($conn, $query)or die(mysql_error());
if (!mysqli_num_rows($r)==0) {
// Adds all of the results to the CSV file
while ($row = mysqli_fetch_array($r)) {
$pnfn = ucwords(strtolower($row[1]));
$dataRow = [$row[0], $row[1], $row[2]];
}
$pnfn = preg_replace('/\s+/', '', $pnfn);
$filename = $pnfn . "-" . $timestamp . ".csv";
// Set headers for the CSV file
header("Content-type: application/csv");
header("Content-Disposition: attachment; filename=" . $filename);
$csvHeader[] = "Pub Information:";
fputcsv($fp, $csvHeader);
$pubHeader = ["Outlet Code", "Pub Short Address", "Regional Code"];
fputcsv($fp, $pubHeader);
fputcsv($fp, $dataRow);
}
$csvHeader2[] = "Points Of Interest:";
fputcsv($fp, $csvHeader2);
// Query to retrieve all of the column names in the Entertainment table (are the same for the other 3) so that
// they can appear at the top of the CSV file.
$query = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA='enterprisepoi_342' AND TABLE_NAME='poi'";
$r = mysqli_query($conn, $query)or die(mysql_error());
// Adds the column names to an array
while ($row = mysqli_fetch_array($r)) {
$header[] = $row[0];
}
array_push($header, "Distance");
fputcsv($fp, $header);
$query = $results;
// Performs the query again to get the results to export
$r = mysqli_query($conn, $query)or die(mysql_error());
if (!mysqli_num_rows($r)==0) {
// Adds all of the results to the CSV file
while ($row = mysqli_fetch_array($r)) {
$distance = number_format($row["distance"], 2, ".", "");
$dataRow = [$row[0], $row[1], $row[2], $row[3], $row[4], $row[5], $row[6], $distance];
fputcsv($fp, $dataRow);
}
// Exit so that the rest of the HTML in the document does not appear in the
// CSV file.
exit;
}
}