Alex
May 28, 2010, 6:39pm
1
Hello everyone,
I’m fairly new to PHP still.
The following code from one of my PHP pages is throwing a parse error. In fact, both of these if statements throw a parse error - but when removed the error is resolved.
Can anyone help me to identify where the error in this code is?
if(array_key_exists('orderBy', $_GET) && in_array($_GET['orderBy'], $orderByFields){
$orderBy = $_GET['orderBy'];
}
if(array_key_exists('direction', $_GET) && in_array($_GET['direction'], array('DESC', 'ASC',){
$direction = $_GET['direction']
}
I’m sure that it’s stupid-simple, but I can’t seem to figure it out.
Thanks in advance,
Alex
if(array_key_exists('orderBy', $_GET) && in_array($_GET['orderBy'], $orderByFields)) // ")" added at the end
{
$orderBy = $_GET['orderBy'];
}
if(array_key_exists('direction', $_GET) && in_array($_GET['direction'], array('DESC', 'ASC'))) // two ")" added at the end, "," removed after 'ASC'
{
$direction = $_GET['direction']
}
And, instead of array_key_exists(‘orderBy’, $_GET) I would just use isset($_GET[‘orderBy’]) but that may be personal preference
Alex
May 28, 2010, 8:06pm
3
rpkamp:
if(array_key_exists('orderBy', $_GET) && in_array($_GET['orderBy'], $orderByFields)) // ")" added at the end
{
$orderBy = $_GET['orderBy'];
}
if(array_key_exists('direction', $_GET) && in_array($_GET['direction'], array('DESC', 'ASC'))) // two ")" added at the end, "," removed after 'ASC'
{
$direction = $_GET['direction']
}
And, instead of array_key_exists(‘orderBy’, $_GET) I would just use isset($_GET[‘orderBy’]) but that may be personal preference
Thanks man, that took care of it.