fakierock Posted August 28, 2013 Share Posted August 28, 2013 Hi guys,I have a CMS system which I've spent the last week fixing. It's built in PHP, and now I'm stuck on the most simplest of tasks. I can't figure out why I am receiving an "undefined variable" error within this block of code. Any help would be greatly appreciated. function track_app($app_id, $lang_code, $str, $instance) { $lang_id = get_lang_id($lang_code); if ($instance > 0) { if ($str == 'LOAD_APP' || $str == 'APP_LOADED') { $query = "INSERT INTO `tracking` ( `APPLICATION_ID`, `LANG_ID`, `INFO`, INSTANCE_ID ) VALUES ( $app_id, $lang_id, '$str', $instance )"; } mysql_query("INSERT INTO `tracking_backup` ( `APPLICATION_ID`, `LANG_ID`, `INFO`, INSTANCE_ID ) VALUES ( $app_id, $lang_id, '$str', $instance )"); mysql_query("UPDATE `instances` SET ACTIVE = 1 WHERE INSTANCE_ID = $instance"); } else { $query = "INSERT INTO `tracking` ( `APPLICATION_ID`, `LANG_ID`, `INFO` ) VALUES ( $app_id, $lang_id, '$str' )"; } mysql_query($query); } Quote Link to comment https://forums.phpfreaks.com/topic/281640-undefined-variable/ Share on other sites More sharing options...
mac_gyver Posted August 28, 2013 Share Posted August 28, 2013 it would probably help if you shared the variable name that's not defined and at which line in the posted code the error is occurring at. Quote Link to comment https://forums.phpfreaks.com/topic/281640-undefined-variable/#findComment-1447175 Share on other sites More sharing options...
fakierock Posted August 28, 2013 Author Share Posted August 28, 2013 Below is the error message I'm getting: PHP Notice: Undefined variable: query in /var/www/vhosts/apphosts.co.uk/httpdocs/v2/project_php/track.php on line 61 line 61 - mysql_query($query); Thanks Quote Link to comment https://forums.phpfreaks.com/topic/281640-undefined-variable/#findComment-1447178 Share on other sites More sharing options...
PaulRyan Posted August 28, 2013 Share Posted August 28, 2013 (edited) For that to happen $instance is greater than 0 AND $str does not equal 'LOAD_APP' or 'APP_LOADED'. Looks like you need to add some more debugging inside the function to return an error or something if that occurs. Edited August 28, 2013 by PaulRyan Quote Link to comment https://forums.phpfreaks.com/topic/281640-undefined-variable/#findComment-1447190 Share on other sites More sharing options...
thodanga Posted August 30, 2013 Share Posted August 30, 2013 Try this logic tweak... function track_app($app_id, $lang_code, $str, $instance) { $lang_id = get_lang_id($lang_code); $query = "INSERT INTO `tracking` ( `APPLICATION_ID`, `LANG_ID`, `INFO` ) VALUES ( $app_id, $lang_id, '$str' )"; if ($instance > 0) { if ($str == 'LOAD_APP' || $str == 'APP_LOADED') { $query = "INSERT INTO `tracking` ( `APPLICATION_ID`, `LANG_ID`, `INFO`, INSTANCE_ID ) VALUES ( $app_id, $lang_id, '$str', $instance )"; } mysql_query("INSERT INTO `tracking_backup` ( `APPLICATION_ID`, `LANG_ID`, `INFO`, INSTANCE_ID ) VALUES ( $app_id, $lang_id, '$str', $instance )"); mysql_query("UPDATE `instances` SET ACTIVE = 1 WHERE INSTANCE_ID = $instance"); } mysql_query($query); } Quote Link to comment https://forums.phpfreaks.com/topic/281640-undefined-variable/#findComment-1447400 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.