0

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?

  • 1
    Please check error_logs you will find the error. – Avinash Rathod Nov 03 '20 at 13:10
  • Does this answer your question? [mysqli\_fetch\_assoc() expects parameter / Call to a member function bind\_param() errors. How to get the actual mysql error and fix it?](https://stackoverflow.com/questions/22662488/mysqli-fetch-assoc-expects-parameter-call-to-a-member-function-bind-param) – Dharman Nov 03 '20 at 13:24
  • [Doesn't work](http://idownvotedbecau.se/itsnotworking/) isn't a useful description of the problem. – Quentin Nov 03 '20 at 13:37
  • This happend to me once because I was using older php version on server and latest on localhost.. I'm not sure if this is your issue but you can check that too. – Akash Desai Nov 03 '20 at 14:53

1 Answers1

0

Prepend at the beginning of the file errors reporting, which is usually "Off" on production servers.

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

Hope, this will help you to diagnose the issue. Otherwise, see log files for errors.

Alex Khimich
  • 788
  • 9
  • 10