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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Var 11 auto converted to 13

Status
Not open for further replies.

Zhris

Programmer
Aug 5, 2008
254
GB
Hello,

Every time I use a query param with the value 11 or 2011, its automatically converted to 13 or 2013. In fact anything below 12 or 2012 is converted. Example:

Code:
// /test.php?Year=11

<?php
	$year = $_GET['Year'] | '12';
	echo "$year";
?>

I'm assuming its recognizing that the value is a date that has passed. Why would it do this / how to I go about resolving it.

Thanks,

Chris
 
Quick update. I'm getting varying results typing different numbers in as the value. Absolutely no idea why.
 
Last update. Looks like its to do with my method of using the 'or' operator to ensure the value defaults to "12". My question is then, how do I set a default value in one line.

Thanks,

Chris
 
The comparison operator is 2 pipes || not one. What you are doing there is the bitwise 'OR' operation of your value and 12.

PHP online manual said:
$a | $b Or (inclusive or) Bits that are set in either $a or $b are set.

What you want to use is a ternary operator or inline conditional.
Code:
$result = action ? value : else;

If action is true value is set, otherwise the else part is set, so:


Code:
  $year = [red]isset([/red]$_GET['Year'][red])[/red] [blue][b]?[/b][/blue] $_GET['Year'] [blue][b]:[/b][/blue] '12';




----------------------------------
Phil AKA Vacunita
----------------------------------
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.

Web & Tech
 
Hi vacunita,

Thanks alot, that did the trick.

Chris
 
Glad I could help.

----------------------------------
Phil AKA Vacunita
----------------------------------
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.

Web & Tech
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top