Click here to Skip to main content
15,918,041 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
PHP
<?php
date_default_timezone_set("As<pre>ia/Hong_Kong");
$treg = date("Y-m");
$ip = $ip;
$mycount_id1 = $_SESSION['count_id'];
if(isset($_SESSION['uid']))
	{
	$myuid1 = $_SESSION['uid'];
	$test1 = $_SESSION['type'];
	if($test1 == "0")
		{
		$myuid1 = $_SESSION['uid'];
		$mygrid1 = "0";
		}
	elseif($test1 == "3")
		{
		$mygrid1 = $_SESSION['uid'];
		$myuid1 = "0";
		}
	}
else
	{
	$myuid1 = "0";
	$mygrid1 = "0";
	}
if(isset($_SESSION['ins_id']))
	{
	$myins_id1  = $_SESSION['ins_id'];
	}
else
	{
	$myins_id1 = "0";
	}
include("bot1.php");
if($oinkcaboink1 == "0")
	{
if(isset($count_iis))
	{
	$count_artid1 = "0";
	$query1 = mysql_query("SELECT * FROM issue WHERE iis = '$count_iis'");
	while($row1 = mysql_fetch_assoc($query1))
		{
		$dbarch_id1 = $row1['arch_id'];
		}
	$query = mysql_query("SELECT * FROM count_monthly WHERE iis='$count_iis' AND uid='$myuid1' AND grid='$mygrid1' AND country_code='$mycount_id1' AND ins_id='$myins_id1' AND ipaddress='$ip' AND treg='$treg'");
	$num = mysql_num_rows($query);
	if($num != "0")
		{
		while($row = mysql_fetch_assoc($query))
			{
			$iis_count = $row['iis_count'];
			$hits = $row['hits'];
			$ct_id = $row['ct_id'];
			$hits++;
			}
		$iis_count++;
		$update = mysql_query("UPDATE count_monthly SET iis_count='$iis_count', hits='$hits' WHERE ct_id = '$ct_id'");
		}
	else
		{
		$add = mysql_query("INSERT INTO count_monthly VALUES ('','$dbarch_id','','$count_iis','1','0','0','$myuid1','$mygrid1','$mycount_id1','$myins_id1','$ip','0','0','$treg','1')");
		}
	}
elseif(isset($count_artid))
	{
	$count_iis = "0";
	$query1 = mysql_query("SELECT * FROM article WHERE artid = '$count_artid'");
	while($row1 = mysql_fetch_assoc($query1))
		{
		$dbiis = $row1['iis'];
		$query2 = mysql_query("SELECT * FROM issue WHERE iis = '$dbiis'");
		while($row2 = mysql_fetch_assoc($query2))
			{
			$dbarch_id = $row2['arch_id'];
			}
		}
	$query = mysql_query("SELECT * FROM count_monthly WHERE artid='$count_artid1' AND uid='$myuid1' AND grid='$mygrid1' AND country_code='$mycount_id' AND ins_id='$myins_id' AND ipaddress='$ip' AND treg='$treg'");
	$num = mysql_num_rows($query);
	if($num != "0")
		{
		while($row = mysql_fetch_assoc($query))
			{
			$artid_count = $row['artid_count'];
			$ct_id = $row['ct_id'];
			$view = $row['view'];
			$view++;
			}
		$artid_count++;
		$update = mysql_query("UPDATE count_monthly SET artid_count='$artid_count', view = '$view' WHERE ct_id = '$ct_id'");
		}
	else
		{
		$add = mysql_query("INSERT INTO count_monthly VALUES ('','$dbarch_id','','$dbiis','0','$count_artid','1','$myuid1','$mygrid1','$mycount_id1','$myins_id1','$ip','0','0','$treg','1')");
		}
	}
	}
>

What I have tried:

i tried to rename the variable but nothing happens still showing the same notice/error
Posted
Updated 26-Apr-17 20:20pm
v3
Comments
mitch_nitro_ 26-Apr-17 23:22pm    
the bold block is the line 45

1 solution

without running this code dump myself, the first thing i see is that it appears your issue is that your variable $mygrid is out of scope of the SELECT statement on line 45.

I'm a bit rusty on my PHP but it looks like you've declared your varaible inside a nested if statement or the else statement which keeps it within the scope of that if/else

PHP
if(isset($_SESSION['uid']))
	{
	$myuid1 = $_SESSION['uid'];
	$test1 = $_SESSION['type'];
	if($test1 == "0")
		{
		$myuid1 = $_SESSION['uid'];
		
	$mygrid1 = "0";
		}
	elseif($test1 == "3")
		{
		$mygrid1 = $_SESSION['uid'];
		$myuid1 = "0";
		}
	}
else
	{
	$myuid1 = "0";
	$mygrid1 = "0";
	}


You are trying to access the variable $mygrid outside the scope of that if/else statement which is why you are getting an undefined error.

Move the variable declaration mygrid1 outside the if(isset block and then it should be within scope for the select statement to have it defined.

So something like this

PHP
$mygrid1 = "DECLARE HERE";
if(isset($_SESSION['uid']))
	{
//Set mygrid1 to whatever value it needs to be
}
else
{
//Set mygrid1 to whatever value it needs to be
}

// Run select statement here with $mygrid1
 
Share this answer
 
Comments
mitch_nitro_ 27-Apr-17 2:30am    
Thank u. its done, no error anymore

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900