Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top