Jump to content

Recommended Posts

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);
 
}
Link to comment
https://forums.phpfreaks.com/topic/281640-undefined-variable/
Share on other sites

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 by PaulRyan
Link to comment
https://forums.phpfreaks.com/topic/281640-undefined-variable/#findComment-1447190
Share on other sites

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);
}
Link to comment
https://forums.phpfreaks.com/topic/281640-undefined-variable/#findComment-1447400
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.