0

This is my code.

  <?php

  $name = 'John Doe';
  echo 'My name is $name';
  echo "I am from $_COOKIE['mylocation']";

i got an error from this

   Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in : eval()'d code on line 3

if any one know about this please help me.

deepu sankar
  • 4,335
  • 3
  • 26
  • 37

2 Answers2

1

The variables should not be enclosed in the quotes..It should be concatenated using . after closing the quotes

Close the single quotes in echo before $name as well as $_COOKIE['mylocation']

 <?php

  $name = 'John Doe';
  echo 'My name is'.$name;
  echo "I am from". $_COOKIE['mylocation'];
affaz
  • 1,191
  • 9
  • 23
0

Remove the ':

<?php

  $name = 'John Doe';
  echo 'My name is $name';
  echo "I am from $_COOKIE[mylocation]";

Beware of XSS vulnerability!

Veve
  • 6,643
  • 5
  • 39
  • 58