-2

In the following code fragment, the value of $key (line 39) is not being substituted. Can someone suggest why?

The variable is receiving the correct value as I have debugged for that in line 37 and it is correct.

If I replace the variable with an integer then the code run correctly i.e. it opens the form and executes a query returning the expected records.

Why will the substitution not take place within php and what must I do for the substitution to take place?

Thanks in advance.

 37 //var_dump($key);
 38 //echo "<br>";
 39 header( 'Location: http://xx.x.80.94/ants/connie/allExhibitsForEvent.php?id=$key' );
 40 ?>
Tony
  • 59
  • 1
  • 5
  • 1
    If anything this should have been closed as a typo. The duplicate question doesn't address single vs. double quoted strings. –  Jul 04 '14 at 03:38
  • I was going to VTC for that reason, but the reason also says 'is not helpful for future users' - this question likely is helpful. – sevenseacat Jul 04 '14 at 03:40
  • This is a better duplicate question: http://stackoverflow.com/questions/18357786/single-quotes-and-double-quotes-in-php –  Jul 04 '14 at 03:40
  • no problem let me reopen .... btw i could not cast close again :( – NullPoiиteя Jul 04 '14 at 03:42

3 Answers3

2

If you want string interpolation of variables, use double quotes:

header( "Location: http://xx.x.80.94/ants/connie/allExhibitsForEvent.php?id=$key" );
1

You have 2 alternatives

1. Change `'` to `"` so that it becomes
header( "Location: http://xx.x.80.94/ants/connie/allExhibitsForEvent.php?id=$key" );

2. Use something like this
header( 'Location: http://xx.x.80.94/ants/connie/allExhibitsForEvent.php?id='.$key );
rcs
  • 6,713
  • 12
  • 53
  • 75
0

Your using the $key inside of a single quoted string.. Try to use the double quote and it will works well.

header( "Location: http://xx.x.80.94/ants/connie/allExhibitsForEvent.php?id=$key" );
NullPoiиteя
  • 56,591
  • 22
  • 125
  • 143
Imat
  • 500
  • 2
  • 4
  • 15