-1

I'm using XAMPP and have a php site that should print out the input passed by GET. The URL looks like http://127.0.0.1/profile.php?id=643bqmxf9rj62.

In the php file I have this code:

$accId= $_GET['id'];
echo "accId = " + $accIdd;

What gets printed is simply 643, without the accId =. Anything after the first character that isn't a digit gets cut off.

When I pass bqmxf9rj62 in the URL without numbers in front, my script prints 0.

I have made websites before but I can't figure out why this is happening.

spacecoyote
  • 1,909
  • 3
  • 19
  • 24

1 Answers1

4

You're using the wrong operator for concatenation. In php, the concatenation operator is a period/dot: .

So your code should be:

echo "accId = " . $accIdd;

A plus sign + is the concatenation operator in JavaScript.

Using the + here means you're actually adding things together, not concatenating, so PHP is thinking blah + 643etc = 643.

m59
  • 43,214
  • 14
  • 119
  • 136
  • Wow, it's really been a while since I last touched PHP. This is hilarious considering how angry it made me by now. Thank you. Accepting your answer as soon as the site lets me. – spacecoyote Feb 17 '14 at 19:05
  • Here are some more details about why PHP designers chose to use the dot operator instead of plus: http://stackoverflow.com/questions/1866098/why-a-full-stop-and-not-a-plus-symbol-for-string-concatenation-in-php – gat Feb 17 '14 at 19:05