Assigning GET var to regular var.
I am having a strange issue that I think may be a syntax problem but I dont understand completely.
Here is my code:
PHP Code:
if(isset( $_GET [ 'famType' ]))
{
$famTypeStr = $famTypes [ $_GET [ 'famType' ]];
echo "<script>alert('famType: " . $_GET [ 'famType' ] . " | " . $famTypeStr . "')</script>" ; //DEBUG
}
if(isset( $_GET [ 'geo' ]))
{
$subgeoStr = $_GET [ 'geo' ];
echo "<script>alert('geo: " . $_GET [ 'geo' ] . " | " . $famTypeStr . "')</script>" ; //DEBUG
}
I am requesting the page containing the above code passing the get parameters as follows: ../page.php?famType="M01"&geo="2"
The alert box pops up for both if statements and it prints the contents of the get variables as desired, but both $famTypeStr and $subgeoStr are null.
Is there something wrong with the assignment syntax I'm using in these cases?
One bit of info I may have forgot to add,
the $famTypes array which is referenced in the assignment of "$famTypeStr" is defined as follows:
PHP Code:
$famTypes = array( "M01" => "X01 - First family" , "M02" => "X02 - Second Family" , );
Have you tried passing the parameters without quotes, like:
../page.php?famType=M01&geo=2
Dave
That does work! Thanks!
So in PHP is there any difference between passing an integer 2 and a string "2"?
You should also check that $_GET['famType'] is a key in $famTypes before attempting to use them together.
PHP Code:
<?php error_reporting (- 1 ); $famTypes = array( "M01" => "X01 - First family" , "M02" => "X02 - Second Family" , ); if(!empty( $_GET [ 'famType' ]) && array_key_exists ( $_GET [ 'famType' ], $famTypes )) { $famTypeStr = $famTypes [ $_GET [ 'famType' ]]; echo "<script>alert('famType: " . $_GET [ 'famType' ] . " | " . $famTypeStr . "')</script>" ; //DEBUG } if(!empty( $_GET [ 'geo' ]) && !empty( $famTypeStr )) { $subgeoStr = $_GET [ 'geo' ]; echo "<script>alert('geo: " . $_GET [ 'geo' ] . " | " . $famTypeStr . "')</script>" ; //DEBUG }
Originally Posted by
DaveRich
That does work! Thanks!
So in PHP is there any difference between passing an integer 2 and a string "2"?
I'm pretty sure when you passed it with the quotes, all 3 characters - quote 2 quote - were in the string, and of course that's not what you were expecting. Attributes in query strings aren't quoted, that's just the way it works, and they end up as strings in the $_GET array.
Dave
Thanks for all the help and information. It is very much appreciated.
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Bookmarks