The following warnings occurred: | ||||||||||||
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
|
Using US classes in AJAX call - Printable Version +- UserSpice (https://userspice.com/forums) +-- Forum: Support Center (https://userspice.com/forums/forumdisplay.php?fid=23) +--- Forum: UserSpice 4.3 and Below (https://userspice.com/forums/forumdisplay.php?fid=26) +--- Thread: Using US classes in AJAX call (/showthread.php?tid=777) |
Using US classes in AJAX call - mckennahampton - 09-26-2017 I'm building am "add to cart" function via AJAX. When I load ini.php in the PHP file I call to in AJAX, it loads successfully, but I can't use any of the classes. The first thing I try to do is make a query call to the users table, andd I get this error: PHP Fatal error: Call to a member function get() on null in... $cart_query = $db->get('users',['username','=',$user->data()->username]); That is the line of code that's throwing the error. I know I'm loading init.php successfully because I can echo something onto the screen. I had some trouble initially installing US on my server due to security measures over the fact I had PHP lower than 5.6. Same thing was happing, I was loading init.php successfully, but it was as if I was loading a blank file, no classes were coming through I could use. I'm wondering if there a security boundary I'm hitting. I've done all I can think of, I've included both the javascript file that my AJAX call is being made from as well of the PHP file my AJAX is calling to the admin pages, they are both passing the "if (!securePage($_SERVER['PHP_SELF'])){die();}" test. Not sure what to do from here, any help would be appreciated. Using US classes in AJAX call - mudmin - 09-26-2017 Hmm. Are you using some sort of parser file? You might need to do $db=DB::getInstance(); Using US classes in AJAX call - mckennahampton - 09-26-2017 That did the trick! I'll have to look into what would've caused that on my end. Thanks for the help! Using US classes in AJAX call - mudmin - 09-27-2017 That AJAX parser file is sort of like writing a function in php. It doesn't have access to the DB unless you exclusively grant it. That's where the db instantiation comes in. It's also a good idea if you do some other checks in that parser file before updating the database. I usually do something like Code: if(hasPerm([2,3,4],$user->data()->id){ Code: //your code Code: }else{ Code: die("You should not be here"); Code: } Using US classes in AJAX call - mckennahampton - 10-01-2017 Got it, thanks for the tip! |