the current page is getting the variables item and code from query string,so according to my code it should go into any of the first three conditions... but its going into the last else conditon.. while echoing the values $a and $i, i am getting 2 and A-1-1 respectively.
$a=$_GET['code'];
$i=$_GET['item'];
if($a==1 && $i!='')
{
header("location:http//:www.abc.com");
}
else if($a==2 && $i!='')
{
header("location:http://www.xyz.com");
}
else if($a==3 && $i!='')
{
header("location:http://www.xpqr.com");
}
else if($a==1)
{
header("location: http://www.a1bc.com");
}
else if($a==2)
{
header("location:http://www.x1yz.com");
}
else if($a==3)
{
header("location:http://www.x1pqr.com");
}
else
{
echo "ERROR";
}
can someone help me find the issue why the if else not working in the expected manner.
you need to use the equality operator: ==
double equal
if($a==1 && $i!='')
single equal is the assignment operator.
In conditions you are writing
if($a=1 && $i!='') // "=" is assignment operator
it should bt
if($a==1 && $i!='')
You are using assignment operator instead of a conditional operator. For the above code the value of a will always be 1
because of the following line of code :
if($a=1 && $i!='')
=
is an assignment operator where as ==
is a conditional operator.
Use ==
in all your if condition.
Hope this will help.
Use ==
in all your if condition. And your header codes
header("location: http:www.abc.com");
Should be like this
header("location: http://www.abc.com"); // you are missing '//' in every header
$a=$_GET['code'];
$i=$_GET['item'];
if($a==1 && !$i)
{
header("location:http//:www.abc.com");
}
else if($a==2 && !$i)
{
header("location:http://www.xyz.com");
}
else if($a==3 && !$i)
{
header("location:http://www.xpqr.com");
}
else if($a==1)
{
header("location: http://www.a1bc.com");
}
else if($a==2)
{
header("location:http://www.x1yz.com");
}
else if($a==3)
{
header("location:http://www.x1pqr.com");
}
else
{
echo "ERROR";
}
use !$i it sets to false.