1

I visit:

http://www.mydomain.com/test.php?loc=1

This should set $location to be 'VC' and print it out to the screen.

But when I do this, I get a zero '0' instead.

What am I doing wrong, why can't I set a string?

<?php
    $loc = $_REQUEST['loc'] ;
if($loc == 1){
$location = 'VC';
echo 'yes';
}
else {
echo "ERROR - Wrong Location code presented";
}   
    echo 'Location: ' + $location;

?>

I started with:

<?php
    $loc = $_REQUEST['loc'] ;
    echo 'Location: ' + $loc;
?>

Where I would visit:

http://www.mydomain.com/test.php?loc=VC

and it would do what I want, but that didn't work.

I must be missing something obvious, but I can't see what. help!

Cheeky Cherub
  • 123
  • 1
  • 2
  • 7

2 Answers2

4

You have to change it this:

<?php
    $loc = $_REQUEST['loc'] ;
    echo 'Location: ' + $loc;
?>

to this:

<?php
    $loc = $_REQUEST['loc'] ;
    echo 'Location: ' . $loc;
?>

PHP's string concatenation operator is the . dot instead of a + as used in JavaScript, etc.

Bojangles
  • 99,427
  • 50
  • 170
  • 208
itsme
  • 575
  • 1
  • 6
  • 15
1

Use $_GET['loc'] instead of $_REQUEST['loc'] and concetenate with a . instead of a + as Mattedgod already stated.

Why $_GET instead of $_REQUEST?? See: Among $_REQUEST, $_GET and $_POST which one is the fastest?

Community
  • 1
  • 1
Wouter Dorgelo
  • 11,770
  • 11
  • 62
  • 80