PHP upgrade from 5.2 to 5.6 the below code stopped working:
After Running it throwing the error: Failed to load resource: the server responded with a status of 500 (Internal Server Error). I am not sure if there is an issue with javascript or PHP itself that is causing the issue. The frontend is loading but it is not fetching the data on the callback.
Any help will be really appreciated. If this is a duplicate of some error or post, please point me towards a necessary answer. If I have done any mistake in writing the question, Please write a comment why are you doing that instead of just blatantly giving me a negative score.
Javascript snippet:
jQuery(document).ready(function() {
// Get data from Outlast Server
var url="https://xxxxx/xxxx/q_data.php?callback=?";
jQuery.getJSON(url, function(rts_data) {
var deck_count = 0, shiplap_count = 0, bnb_b_count = 0, bnb_c_count = 0;
for(var i=0; i<rts_data.length; i++) {
if (rts_data[i].type == "Deck") {
data[0][deck_count] = new Object();
data[0][deck_count].productName = rts_data[i].productName;
data[0][deck_count].coverage = rts_data[i].coverage;
data[0][deck_count].screws = rts_data[i].screws;
data[0][deck_count].gaps = rts_data[i].gaps;
// Insert the data into the Select Box
jQuery('#opt_d').append(jQuery('<option>', { value : deck_count }).text(rts_data[i].productName));
deck_count++;
}
else if (rts_data[i].type == "Shiplap") {
data[1][shiplap_count] = new Object();
data[1][shiplap_count].productName = rts_data[i].productName;
data[1][shiplap_count].coverage = rts_data[i].coverage;
data[1][shiplap_count].screws = rts_data[i].screws;
data[1][shiplap_count].gaps = rts_data[i].gaps;
// Insert the data into the Select Box
jQuery('#opt_s').append(jQuery('<option>', { value : shiplap_count }).text(rts_data[i].productName));
shiplap_count++;
}
else if (rts_data[i].type == "Board and Batton - Cap") {
data[2][bnb_c_count] = new Object();
data[2][bnb_c_count].productName = rts_data[i].productName;
data[2][bnb_c_count].coverage = rts_data[i].coverage;
data[2][bnb_c_count].screws = rts_data[i].screws;
data[2][bnb_c_count].gaps = rts_data[i].gaps;
// Insert the data into the Select Box
jQuery('#opt_bnb_c').append(jQuery('<option>', { value : bnb_c_count }).text(rts_data[i].productName));
bnb_c_count++;
}
else if (rts_data[i].type == "Board and Batton - Base") {
data[3][bnb_b_count] = new Object();
data[3][bnb_b_count].productName = rts_data[i].productName;
data[3][bnb_b_count].coverage = rts_data[i].coverage;
data[3][bnb_b_count].screws = rts_data[i].screws;
data[3][bnb_b_count].gaps = rts_data[i].gaps;
// Insert the data into the Select Box
jQuery('#opt_bnb_b').append(jQuery('<option>', { value : bnb_b_count }).text(rts_data[i].productName));
bnb_b_count++;
}
}
PHP:
<?php
// Connection data
$host = "xxxxxxx";
$username = "xxxxx";
$database = "xxxxx";
$password = "xxxxx";
// Opens a connection to a mySQL server
$connection = mysql_connect ($host, $username, $password);
if (!$connection) {
die("Not connected : " . mysql_error());
}
// Set the active mySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
die ("Can\'t use db : " . mysql_error());
}
// Set the where clause
$where = "";
switch(@$_GET['type']) {
case 'shiplap':
$where = "WHERE type = 'Shiplap'";
break;
case 'deck':
$where = "WHERE type = 'Deck'";
break;
case 'bnb_base':
$where = "WHERE type = 'Board and Batton - Base'";
break;
case 'bnb_cap':
$where = "WHERE type = 'Board and Batton - Cap'";
break;
default:
$where = "";
break;
}
// Run the query
$query = "SELECT * FROM `site_products` {$where} ORDER BY productID ASC";
$result = mysql_query($query);
if (!$result) {
die("Invalid query: " . mysql_error());
}
// Declare Variables
$data_shiplap = array();
$shiplap_i = 0;
// Get the data and divide
while ($row = @mysql_fetch_assoc($result)) {
$data_shiplap[$shiplap_i]['productName'] = $row['productName'];
$data_shiplap[$shiplap_i]['coverage'] = $row['coverage'];
$data_shiplap[$shiplap_i]['screws'] = $row['screws'];
$data_shiplap[$shiplap_i]['gaps'] = $row['gaps'];
$data_shiplap[$shiplap_i]['type'] = $row['type'];
$shiplap_i++;
}
echo $_GET['callback']. '('. json_encode($data_shiplap) . ')';
?>