Reputation: 21389
I am getting this error: "Fatal error: Can't use function return value in write context in D:\Programas\wamp\www\away\index.php on line 18". Line 18 being the if statement.
Can anyone help me out on this? Thanks.
$vars = array("first_date_month", "first_date_day", "last_date_month", "last_date_day", "resume_date_month", "resume_date_day", "pay_date_month", "pay_date_day", "pay_time_hour", "pay_time_minutes");
$err_flag = false;
$i = 0;
while ($i < count($vars) and $err_flag == false)
{
if ( (!isset($_GET($vars[$i])) or ($_GET[$vars[$i] == "0") )
$err_flag = true;
$i++;
}
Upvotes: 0
Views: 429
Reputation: 4472
My take at it:
$vars = array("first_date_month", "first_date_day", "last_date_month", "last_date_day", "resume_date_month", "resume_date_day", "pay_date_month", "pay_date_day", "pay_time_hour", "pay_time_minutes");
foreach ($vars as $var) {
if ($err_flag = empty($_GET[$var]))
break;
}
8)
I assume the marked answer has... well.. answered the problems in your code, so just throwing out some optimizations:
Upvotes: 2
Reputation: 253308
Change your line 18 if...
to:
if ( (!isset($vars[$i])) or ($vars[$i] == "0") )
$err_flag = true;
$i++;
This mainly because I -and this is purely personal, I suspect- don't like using the $_GET[...]
throughout the script; assign:
$variable_from_GET[] = $_GET['variable_name'];
and then use the $variable_from_GET
array variable in your conditions which you -I presume- you did since you had a $vars
array.
Upvotes: 0
Reputation: 400912
$_GET
is a variable, an array -- and not a function.
It means you have to use array-access, with []
, to get the data it contains.
So :
$_GET[$vars[$i]]
instead of
$_GET($vars[$i])
for the first time you are using $_GET.
And, for the second time, you forgot to close one ]
; which means you need to use :
$_GET[$vars[$i]]
instead of
$_GET[$vars[$i]
In the end, you while-loop should look like this :
while ($i < count($vars) and $err_flag == false)
{
if ( !isset($_GET[$vars[$i]]) or $_GET[$vars[$i]] == "0" ) {
$err_flag = true;
}
$i++;
}
Note I also added {}
arround the body of the if condition ; this way, if you ever have to add something, you won't risk forgetting those ;-)
Upvotes: 0
Reputation: 54056
Your code is a mess.
$_GET is an associative array and not a function (you are using the function call syntax passing $vars[$i] as an argument). In the second $_GET there's one ] missing.
Line 18 should be:
if ( (!isset($_GET[$vars[$i]]) or ($_GET[$vars[$i]] == "0") )
Upvotes: 4
Reputation: 1951
Maybe I'm not seeing well, but:
if ( (!isset($_GET($vars[$i])) or ($_GET[$vars[$i] == "0") )
You got a really awful mixup of parenthesis and square brackets. There's no such thing as
$_GET()
Big typo you have to correct.
Upvotes: 8