Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If Problem 5

Status
Not open for further replies.

ZOR

Technical User
Jan 30, 2002
2,963
GB
Should this work? Have tried = 1 and = '1'

if (isset($_POST['B1'])===true AND $_SESSION['Permit']= '1') {
header('location: Ordering1.php');
exit();
}

if (isset($_POST['B1'])===true AND $_SESSION['Permit']= '2') {
header('location: Ordering2.php');
exit();
}

mANY THANKS


 
$_POST['B1'] can be set without it actually containing anything, if it is set it will be true, but you don't need to test for it.

if(isset($_POST['B1'])){
//do stuff
}

or
if(isset($_POST['B1']) && !empty($_POST['B1'])) {
//B1 is set and is not empty ...
}



______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Code:
if ([red]([/red]isset($_POST['B1'])===true[red])[/red][red]&&[/red] ($_SESSION['Permit']=[red]=[/red] '1'))  {...

Dont forget comparisons are done with 2 equal signs. not just one.


----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Many thanks vacunita, I added an = and it works. I did not know that. Also I see conflictions in ===true, does that have to be 3 ='s, sometimes I see only 2. Anyway have a star for fixing that one.

Many thanks KarveR, I use the if ((isset($_POST['B1'])===true)as a redirect action when $_Post is done. Will that fail?, it's just to know which submit button was pressed. Thanks
 
Like I said, you don't need to test (===true) , just plain old if (isset($_POST['B1'])){
//it will work if b1 is set (pressed)
}

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Many thanks, thats answered it clearly for me. Have a star and thanks again.
 

== is equal
=== is identical

for example ...
Code:
$a = "a";

if ($a == 0)
{ 
  echo "a is equal to 0 <br>";
}
if ($a === 0)
{
  echo "a is identical to 0 <br>";
}

(bool)True is equal to any non-zero integer or any string. For a quick brain tease run this code
Code:
if ("true" == false)
{
  echo "True is false";
}
else
{ 
  echo "Truse is not false";
}

However, using the === operator you would get the result you expect. Conversely, if you're a C programmer
Code:
function alwaysFalse()
{
  return 0;
}
if (alwaysFalse() == false)
{
  echo "Was false";
}
else
{  
  echo "Was true";
}
Will do exactly what you expect it to... however changing the conditional to === will reverse the behavior.

Hope I thoroughly confused you enough to read the docs, cause it's an important and useful distinction.
 
skiflyer, that was mint :)

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Thankyou Skiflyer, another star, now I know.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top