Re: Newbie Problem using if statement with &&



On Mon, 02 Jun 2008 06:30:51 +0200, John <JohnMay1248@xxxxxxxxx> wrote:

On Jun 1, 8:10 pm, Jerry Stuckle <jstuck...@xxxxxxxxxxxxx> wrote:
John wrote:
> On Jun 1, 4:42 pm, Jerry Stuckle <jstuck...@xxxxxxxxxxxxx> wrote:
>> John wrote:
>>> Hello all.
>>> I am a PHP newbie and am having an issue using the && in an if
>>> statement. here is the code:
>>> if ($_REQUEST["frmIsEarlyBird"] == "1" && date("Y-m-d") <
>>> $rowWork["wEarlyBird"]) {
>>> die("<h1>The earlybird special has ended.</h1>");
>>> }
>>> Ok when the code runs it and both conditions are true nothing happens.
>>> Testing:
>>> $_REQUEST["frmIsEarlyBird"] is a valid form request and returns a
>>> string of 1 or 0 depending on what im sending.
>>> $rowWork["wEarlyBird"] Has a valid date in it and should validate as
>>> true
>>> If i put these if statements on the page they both work fine.
>>>      if ($_REQUEST["frmIsEarlyBird"] == "1") {
>>>           echo "<br><br>TRUE<br><br>";
>>>      } else {
>>>           echo "<br><br>False<br><br>";
>>>      }
>>>      if (date("Y-m-d") < $rowWork["wEarlyBird"]) {
>>>           echo "<br><br>TRUE<br><br>";
>>>      } else {
>>>           echo "<br><br>False<br><br>";
>>>      }
>>> Thanks in advance for any help
>> When things like this fail, a good first step is to echo the values
>> involved.

>> For instance, right now, what do you have in $_REQUEST["frmIsEarlyBird"]
>> and $rowWork["wEarlyBird"]?  Are you getting what you think you should
>> be getting from date("Y-m-d")?  Also - is $_REQUEST["frmIsEarlyBird"]
>> equal to "1" or 1?  They are two different values.

>> Also, $_REQUEST is generally not a good thing to use,  If it's coming
>> from a POSTed forum, use $_POST.  If it's in the URL, use $_GET.

>> --
>> ==================
>> Remove the "x" from my email address
>> Jerry Stuckle
>> JDS Computer Training Corp.
>> jstuck...@xxxxxxxxxxxxx
>> ==================- Hide quoted text -

>> - Show quoted text -

 > Yeah I have tested the vslues and they are valid. As i said in the
 > original post:
 >
 >
 > Testing:
 >
 > $_REQUEST["frmIsEarlyBird"] is a valid form request and returns a
 > string of 1 or 0 depending on what im sending.
 >
 > $rowWork["wEarlyBird"] Has a valid date in it and should validate as
 > true
 >
 > If i put these if statements on the page they both work fine.
 > (validate as true)
 >
 >      if ($_REQUEST["frmIsEarlyBird"] == "1") {
 >           echo "<br><br>TRUE<br><br>";
 >      } else {
 >           echo "<br><br>False<br><br>";
 >      }
 >
 >      if (date("Y-m-d") < $rowWork["wEarlyBird"]) {
 >           echo "<br><br>TRUE<br><br>";
 >      } else {
 >           echo "<br><br>False<br><br>";
 >      }
 >

(Top posting fixed)

Well, obviously something is not as you describe, because '&&' has a
lower priority than either '==' or '<', which is why I asked you to
verify this.  It's either the data or the statement you supplied doesn't
match what you have in your code.  I'm just trying to eliminate
possibilities.


Sorry bout top posting im new to this group thing as well as php.
Thanks for trying to help me. the code below is an exact paste from
the page. I have the first two if statements there to test the
variables. When the code runs I see TRUE TRUE and thats it the die
never runs. It is my understanding that I am trying to say in my
statement that if $_REQUEST["frmIsEarlyBird"] == "1" is true AND
date("Y-m-d") < $rowWork["wEarlyBird"] is true run the die. I dont
understand why the first two if statetments would each display true
but the third not run.

if ($_REQUEST["frmIsEarlyBird"] == "1") {
echo "<br><br>TRUE<br><br>";
} else {
echo "<br><br>False<br><br>";
}

if (date("Y-m-d") < $rowWork["wEarlyBird"]) {
echo "<br><br>TRUE<br><br>";
} else {
echo "<br><br>False<br><br>";
}

if ($_REQUEST["frmIsEarlyBird"] == "1" && date("Y-m-d") <
$rowWork["wEarlyBird"]) {
die("<h1>The earlybird special has ended.</h1>");
}

If that's the actual code, with nothing in between that can alter either of the variables, I'm thoroughly puzzled. 100% sure you're not misspelling one of the variable names? And have you enabled display_errors and set error_reporting to E_ALL | E_STRICT ?
--
Rik Wasmus
....spamrun finished
.



Relevant Pages

  • Re: Newbie Problem using if statement with &&
    ... Jerry Stuckle ... JDS Computer Training Corp. ... > string of 1 or 0 depending on what im sending. ...
    (comp.lang.php)
  • Re: [PATCH 4/7] tracing/filters: allow user to specify a filter val to be string
    ... and let it answer depending of which filter_pred_*callback we have ... guess whether this is a number or a string, ... depending on the type of the concerned field: ... Even without the filter assignment ambiguity problem it would be ...
    (Linux-Kernel)
  • Re: How to return a variable length substring from a function ?
    ... Depending on the input, the output is either 1 to 3 characters long. ...   colletter = '' ... of 3 things happens - the string is truncated to fit, ...
    (comp.lang.fortran)
  • Re: Extract data from String
    ... I need to split this data out into separate columns. ... a random length depending on the data in it. ... string as it is, the following one shows how it should be split up into ... The same functions can be run from within VBA using the RUN ...
    (microsoft.public.excel.programming)
  • Re: Find & Replace Whole Words
    ... John, I had another thought. ... I do not think Excel has the functionality you require built-in. ... string or a whole string, NOT a whole word within a string. ... I am sure there are ways do this in VBA, but I cannot think of anything ...
    (microsoft.public.excel.programming)