0
Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\wamp\www\test\base.list.php on line 14    

Here comes my code

if(isset($_GET['sortby']))  
{   
$sortby = "ORDER BY $_GET['sortby']";   
}   

Error is at "sortby" line.

sampathsris
  • 21,564
  • 12
  • 71
  • 98
Just Nick
  • 13
  • 5

1 Answers1

1

Change your code to:

$sortby = "ORDER BY {$_GET['sortby']}"

Explanation

As specified in the link Anthony has provided, quoted keys for arrays require "complex" (aka "curly") syntax when embedding expressions in strings.

// Works, quoted keys only work using the curly brace syntax
echo "This works: {$arr['key']}";

And I recommend you to read:

Community
  • 1
  • 1
sampathsris
  • 21,564
  • 12
  • 71
  • 98
  • 1
    Also look at article on curly-braces and string parsing : http://php.net/manual/en/language.types.string.php#language.types.string.parsing.complex – Anthony Oct 13 '14 at 12:24