The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/showthread.php 28 require_once
Warning [2] Undefined array key "" - Line: 1584 - File: inc/functions.php PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/functions.php 1584 errorHandler->error
/inc/functions_post.php 203 usergroup_displaygroup
/showthread.php 1117 build_postbit
Warning [2] Trying to access array offset on value of type null - Line: 1588 - File: inc/functions.php PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/functions.php 1588 errorHandler->error
/inc/functions_post.php 203 usergroup_displaygroup
/showthread.php 1117 build_postbit
Warning [2] Trying to access array offset on value of type null - Line: 1588 - File: inc/functions.php PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/functions.php 1588 errorHandler->error
/inc/functions_post.php 203 usergroup_displaygroup
/showthread.php 1117 build_postbit
Warning [2] Trying to access array offset on value of type null - Line: 1588 - File: inc/functions.php PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/functions.php 1588 errorHandler->error
/inc/functions_post.php 203 usergroup_displaygroup
/showthread.php 1117 build_postbit
Warning [2] Trying to access array offset on value of type null - Line: 1588 - File: inc/functions.php PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/functions.php 1588 errorHandler->error
/inc/functions_post.php 203 usergroup_displaygroup
/showthread.php 1117 build_postbit
Warning [2] Trying to access array offset on value of type null - Line: 1588 - File: inc/functions.php PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/functions.php 1588 errorHandler->error
/inc/functions_post.php 203 usergroup_displaygroup
/showthread.php 1117 build_postbit
Warning [2] Trying to access array offset on value of type null - Line: 1588 - File: inc/functions.php PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/functions.php 1588 errorHandler->error
/inc/functions_post.php 203 usergroup_displaygroup
/showthread.php 1117 build_postbit
Warning [2] Trying to access array offset on value of type null - Line: 1588 - File: inc/functions.php PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/functions.php 1588 errorHandler->error
/inc/functions_post.php 203 usergroup_displaygroup
/showthread.php 1117 build_postbit
Warning [2] Undefined array key "useravatar" - Line: 6 - File: inc/functions_post.php(931) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/functions_post.php(931) : eval()'d code 6 errorHandler->error
/inc/functions_post.php 931 eval
/showthread.php 1117 build_postbit
Warning [2] Undefined array key "userstars" - Line: 11 - File: inc/functions_post.php(931) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/functions_post.php(931) : eval()'d code 11 errorHandler->error
/inc/functions_post.php 931 eval
/showthread.php 1117 build_postbit





× This forum is read only. As of July 23, 2019, the UserSpice forums have been closed. To receive support, please join our Discord by clicking here. Thank you!

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
function didn't work
#1
Hello all from Soggy Houston, TX!

I tried this function:


function getConfig ($search='')
{
require_once 'users/init.php';
require_once $abs_us_root.$us_url_root.'users/includes/header.php';
$config = $db->query("select options from config where setting = ?",array($search));
$back = $config->first()->options;
return $back;
}

and received the following errors:

Notice: Undefined variable: abs_us_root in C:\xampp\htdocs\follower\function.php on line 7

Notice: Undefined variable: us_url_root in C:\xampp\htdocs\follower\function.php on line 7

Notice: Undefined variable: db in C:\xampp\htdocs\follower\function.php on line 8

Fatal error: Uncaught Error: Call to a member function query() on null in C:\xampp\htdocs\follower\function.php:8 Stack trace: #0 C:\xampp\htdocs\follower\index.php(11): getConfig('logo') #1 {main} thrown in C:\xampp\htdocs\follower\function.php on line 8

This was to the call of: $set = getConfig('logo');

Can anyone point me where I went wrong?
  Reply
#2
Where did you make this function at? And why is your init call in it? You shouldn't need to call your init or your header in a function.
  Reply
#3
I have a file of just functions. I had read https://userspice.com/documentation-db-class/ perhaps I misunderstood it. I did replace it with $db = DB::getInstance(); and it worked fine.
  Reply
#4
Usually these sorts of functions go in usersc/custom_functions.php

I think the function would look more like this...
function getConfig ($search)
{
$config = $db->query("select options from config where setting = ?,array($search));
$back = $config->first();
return $back;
}

Then you would call it by saying
$options = getConfig('myoption');

I'm guessing your config table is setup with basically 3 columns..
id(auto incrementing)
options (the actual options in varchar)
setting (whatever you call the options in varchar)
  Reply
#5
Going to hop in on this thread. I also need help with using Class variables on the usersc/custom_functions.php

Same with OP, I had to use $db = DB::getInstance(); but I'm now having issues with the notification.

Is there an easier way to get the functions to call Class variables?
  Reply
#6
Functions are sort of like standalone programs. If you want them to have access to things outside them, you usually have to bring it inside the scope of the function. That means instantiating the class, calling the function, or using a global. For instance... Iirc, you can do global $db; to use the db class that was already instantiated in the header. This can get weird if you reuse that variable name somewhere else on the page.
  Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)