Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP: AJAX request to PHP
    text
    copied!<p>So I'm having a problem with including a file on a PHP page called from an AJAX request:</p> <pre><code>$(document).ready(function() { $("#image-status").html('Processing images...'); }); function process_images(files) { $.ajax ({ type: "POST", url: "includes/imageprocessor.php", data: {files: JSON.stringify(files)}, success: function(data){ $("#image-status").html(data); } }); } </code></pre> <p>I'm trying this require_once on imageprocessor.php:</p> <pre><code>require_once("db_connect.php"); </code></pre> <p>Which is also in the include directory, and works: I just used it on another page to run an insert that worked just fine. But when I try to run:</p> <pre><code>function get_files($id) { $query = $db-&gt;prepare("SELECT * FROM files INNER JOIN file_profile_join ON files.id = file_profile_join.file_id WHERE file_profile_join.profile_id = " . $id . " GROUP BY files.id"); try { $query-&gt;execute(); $rows = $query-&gt;fetch(); } catch (PDOException $e) { die($e-&gt;getMessage()); } } </code></pre> <p>later on in imageprocessor.php, it errors out:</p> <pre><code>Fatal error: Call to a member function prepare() on a non-object in /home/yogabopvolume26/theprivatesector.org/epic/includes/imageprocessor.php on line 90 </code></pre> <p>Like it's not requiring db_connect in the first place (that's where $db is declared). But it's also not returning an error that it can't find db_connect.php. </p> <pre><code>basename(__DIR__) </code></pre> <p>on imageprocessor.php (echoed through the AJAX request) returns "include."</p> <p>I've tried using both an absolute URL and root path in the require_once, but then it neither errors out nor continues with imageprocessor.php: no echoes from that file after the require_once are returned. I also can't get the current session from session_start (I can print_r $_SESSION from the originary page [profile.php], so the session is active). Maybe they're related? I can't figure out what's wrong.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload