php


fatal error in php


if(!empty($home) && !empty($title) && !empty($meta))
{
function updcfg($condition,$status){
$db->query("UPDATE site_config SET status = '".$status."' WHERE condition = '".$condition."' ");
}
updcfg("home",$home);
updcfg("title",$title);
updcfg("meta",$meta);
updcfg("news",$news);
}
the current code that you see above is not working and giving me this error :
Fatal error: Call to a member function query() on a non-object in /home/main.php on line 20
I deleted the function.. and the code worked with no problems ! can anyone tell what is wrong with the code?
pass $db in the function.
function updcfg($condition,$status,$db){
$db->query("UPDATE site_config SET status = '".$status."' WHERE condition = '".$condition."' ");
}
updcfg("home",$home,$db);
You should put the function outside of the if statement.
$db is not defined inside the updcfg function, and is not defined as global. So, there are three oprions:
1. use global keyword:
function updcfg($condition,$status){
global $db;
2. pass $db to the function arguments : function updcfg($condition, $status, $db)
3. init $db inside the function (the way you do it)
please load database class before calling query method
function updcfg($condition,$status){
$this->load->database();
$this->db->query("UPDATE site_config SET status = '".$status."' WHERE condition = '".$condition."' ");
}
You need to initialize the $db variable. If you have initialized before is not alive inside the updcfg function, but you can pass the $db context as parameter:
function updcfg($condition, $status, $db){
$db->query("UPDATE site_config SET status = '".$status."' WHERE condition = '".$condition."' ");
}
$db = new ....
#Now you can do this
updcfg("home",$home, $db);
updcfg("title",$title,$db);
updcfg("meta",$meta,$db);
updcfg("news",$news,$db);

Related Links

Updating mysqli multiple columns error PHP [duplicate]
Creating model event not firing in observer
Loading data into the current view
Laravel doctrine only returning single attribute from findAll() query
How do I save multiple values of record in PHP to enter in database
Could not allow to take backup on akkeba backup in joomla 3.5.1
how to merge two different CI application to become one application?
php exec not getting whole output
Error when setting up VirtualHost in Wamp - The ServerName has syntax error in file httpd-vhosts.conf
PHP: Cannot read from a .txt file
How to upload image to server using angularjs?
My PHP file upload script hangs if file size > ~7.5MB, despite changing ini settings
PHP password_verify() not validating passwords
Why does my Wordpress Query not work on non Index Pages?
simplexml_load_file(): Unable to locate certificate CN
Laravel: Enforce unique rule if userid is different

Categories

HOME
oracle
entity-framework
svn
transactions
dry
slider
jersey-2.0
gallery
biztalk-2010
amp
navigation
sympy
phpseclib
gtk
sap-fiori
android-externalstorage
l20n
exec-maven-plugin
infrared
home
social-tables
altium-designer
ava
cell
pdf.js
list-comprehension
openbravo
points
history.js
onchange
substance
intune
dotcms
tightvnc
appcode
listjs
image-optimization
polyml
amazon-kms
subclassing
stackpanel
ms-dos
android-n
python-jira
angular-datatables
opal-framework
fiware-wirecloud
virtual-memory
git-tfs
moinmoin
asihttprequest
swift2.3
icecast
non-linear-regression
ilrepack
visual-format-language
http-basic-authentication
clrs
sesame
apache-modules
ltrace
cocoa-bindings
pjax
metabase
okio
fuzzer
pyaudio
carmen
android-4.2-jelly-bean
deferred-rendering
adp
onepage-checkout
lowercase
srv-record
espresso
dynamics-ax-2012-r2
kefir.js
whitespace-language
scala-macros
mgwt
camus
mathematical-expressions
python-c-extension
subview
htmltidy
jcheckbox
cakephp-2.2
wicket-1.5
window-resize
mobile-country-code
bittorrent-sync
webaii
jack
spring-social-linkedin
principalcontext
strdup
grails-2.3
san
flv
axacropdf
ntlmv2
struts2-json-plugin
playorm
liveconnect
mkannotation
will-paginate
gaelyk
uninstaller
tabbarcontroller
activex-exe

Resources

Encrypt Message