Hi there. Still a newbie question...
a) I tested my code at localhost (my computer) and ALL was good. Now I uploaded my files to remote site and I can't get my page to work. There is an Ajax call to database. Do I need to change the URL in the ajax? Now it's something like php/file.php. Then there is the json file and the config (username, password, etc). The config file is different with the new user name, etc.

b) while develing my page, I could use firebug, etc and get the error (no such file, no such picture, etc). Is there a way to do the same with the remote site?

Thank you so much!

Dani AI

Generated

That problem usually comes down to one of a few practical differences between localhost and a hosted site: the AJAX path resolving differently, cross-origin/mixed-content rules, the remote PHP script failing before it returns JSON (but errors are suppressed), or the DB credentials/host not matching the hosting environment. Start by treating the AJAX call itself as the primary suspect — if the browser never gets a valid JSON response the page will look like “nothing happens” even though your client code is fine.

Use the browser developer tools on the remote site (Network -> XHR, Console). Load the page from the remote URL, watch the XHR entry for the call, and check:

  • request URL that the browser is actually calling (relative vs absolute path),
  • HTTP status code (200 / 404 / 500 / 302),
  • response body (HTML error pages or PHP warnings will break JSON parsing),
  • response headers (Content-Type should be application/json),
  • console messages (CORS or mixed-content warnings if HTTPS vs HTTP).
    If you see 404, fix the path; 500 means enable server-side error output or check your host error log; CORS requires server headers or JSONP.

On the server side verify the exact PHP endpoint and DB connection used by your AJAX call. Put a very small, temporary test file that uses the same config and returns the database name and any connect error so you can confirm the script runs and reaches the intended database. Example (temporary; remove or secure after debugging):

<?php
error_reporting(E_ALL);
ini_set('display_errors','1');
// replace with same config values your AJAX script uses
$h='DB_HOST'; $u='DB_USER'; $p='DB_PASS'; $db='DB_NAME';
$conn = new mysqli($h,$u,$p,$db);
if ($conn->connect_error) { echo json_encode(['ok'=>false,'error'=>$conn->connect_error]); exit; }
$r = $conn->query("SELECT DATABASE() AS d")->fetch_assoc();
echo json_encode(['ok'=>true,'database'=>$r['d']]);
?>

A few final notes: prefer absolute paths (or a leading slash) for your AJAX URL, ensure you call https:// when the page is served over HTTPS, and check that the DB user is permitted to connect from the host your site runs on. As suggested, host logs are useful, but the MySQL or general logs you saw don’t by themselves prove your PHP script used the same credentials — the quick test above will. Once fixed, remove debug output and keep your config file outside the web root or otherwise protected.

Recommended Answers

All 7 Replies

Yes, the same tools also work on a remote website. Also check your server's error logs (in case of PHP errors).

Pardon for my ignorance, how do I do that?
I am using bluehost and just quit 1and1 for this current matter.

If there is an error in PHP, there should be an error_log created in that folder.

Thanks for your input. There was no error while developing the web page (my localhost). The error just came up when I needed to change the Ajax url and the config doc. It must be there. I will ask them about this error-log tomorrow morning.... UPDATE. I think I found it here.

UPDATE 2. I found it. Please bear with me as I learn how to do this. There are basically two kinds of messages.
The database has just one entry for test now.
a)

Thu Jul 25 19:00:28 2013
Query_time: 6.085445 Lock_time: 0.000127 Rows_sent: 1 Rows_examined: 1

SET timestamp=1374800428;
SHOW DATABASES

Thu Jul 25 19:00:35 2013
Query_time: 7.304551 Lock_time: 0.002517 Rows_sent: 1 Rows_examined: 550

SET timestamp=1374800435;
SELECT COUNT(*) FROM information_schema.COLUMNS

Thu Jul 25 19:01:00 2013
Query_time: 25.135463 Lock_time: 0.000063

It goes on for several lines with info like that.

b)
The other is very concise.

Thu Jul 25 21:02:49 2013
Query_time: 5.379344 Lock_time: 0.000104 Rows_sent: 2 Rows_examined: 2

SET timestamp=1374807769;
SHOW DATABASES

In the console (firebug, chrome, etc) I would find things like this: file does not exist, etc. Does the above show that it's reaching the right database? Since I never saw the right one, I don't undertand the above or the difference. It seems that it's not reading anything.
Thank you for your time.

Find out where the "file does not exist" comes from.

The rest is just database logging, what looks to me from something like PhpMyAdmin.

I mean, while I was building the web page, firebug would say: picture not found. Etc. Now all is good. Now there is no message, all should be working. No message anymore in my console / localhost.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.