Reputation: 3756
I have the following code in php to get variables from a query string
$first_name = $_GET['firstName'];
echo $first_name;
when the query string only contains one value like
index.php/details?firstName=Austin
the value appears on the page like
but for some reason when I try and pass two separate values in the query string like
index.php/details?firstName=Austin&lastName=Davis
and trying to make the values of the variables appear on the next page like so
$first_name = $_GET['firstName'];
$last_name = $_GET['lastName'];
echo $first_name + $last_name;
the value zero appears on the webpage. Why can't pass two values in a query string using the & operator.
Upvotes: 0
Views: 74
Reputation: 24645
+
is the addition operator in php what you are looking for is .
which is the concatenation operator. See more on PHP's Operators
Change
echo $first_name+$last_name;
to
echo $first_name.$last_name;
or better yet
echo $first_name.' '.$last_name;
By using the addition operator you are basically casting the left and right hand side of the operator to numbers (both of which will result in 0 and the sum of which is 0).
Upvotes: 2