I just got my hosting, I uploaded the files from my localhost server, exported the local database and uploaded it to the hosting service. I then created a user with all permissions allowed.
The problem is that when I enter the website the PHP files doing the queries give an Internal server error (500).
I have checked the connection to the database and the version of the PHP with the following code:
<?PHP
$db_servername = "www.website.com";
$db_username = "user";
$db_password = "password";
$db_database = "db";
phpinfo();
$db = mysqli_connect($db_servername, $db_username, $db_password,$db_database);
if (!$db) {
die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
}
echo 'Connected... ' . mysqli_get_host_info($db) . "\n";
?>
The result from this is that the connection to the database is successful and that the PHP version is up to date.
This is the code from the queries php file:
<?php
include('db.php');
$sql = $db ->prepare('...');
$sql -> execute();
$result = $sql -> get_result();
$list = array();
while( $row = $result->fetch_assoc() ) {
$list[] = $row;
}
$final_list = json_encode($list);
echo $final_list;
?>
The query has been checked in the server and it works fine. I've commented sections of the code above to check when is it that it gives an error, and the error comes when I echo the $final_list. Everything else works.
This is the code from the script that calls the query:
$.post("load_articles.php", function(result){
if(! (result == null)){
/* Iterate through results to populate table */
json = result;
for(var i in json){
if(i % 2 == 0 && i < 5){
columnModulus = 0;
}else if(i < 5){
columnModulus = 1;
}else if(i % 2 == 0 && i >= 5){
columnModulus = 2;
}else if(i >= 5){
columnModulus = 3;
}
myData =
'<a href="article.php?articleId=' + json[i].aId + '">' +
'<div class="home-article" id="' + json[i].aId + '">' +
'<img style="margin: auto; display: block;" data-modulus="'+columnModulus+'" src="'+json[i].imagePath+'">'+
'<p class="article-theme">'+json[i].theme+'</p>'+
'<p class="article-title">' + json[i].title + '</p>' +
'</div>'+
'</a>';
appendTo = ".home-container div[data-modulus='"+columnModulus+"']";
$(appendTo).append(myData);
}
}else{
myData += "<div>No comments found</div>";
}
}, "json");
This code works perfectly fine in the localhost, of course changing the database connection details, but it doesn't work on the online server. Any ideas?