Log in

View Full Version : Fatal error: Can't use function return value in write context



zee000
02-20-2010, 03:11 PM
hiii i am new to php can any one check this

<html>
<head>
</head>
<body>
<form method="post">
<input type="date" name="startDate"></td>
<input type="date" name="endDate"></td>
<input type="submit" name="submit">
</body>
</html>

<?php
echo hi;
include"config.php";
echo $_POST[startDate];
echo $_POST[endDate];
$sql="INSERT INTO date VALUES ('','$_POST[startDate]','$_POST[endDate]')";

echo gregoriantojd($endDate)-gregoriantojd($startDate)=gregoriantojd($date);
?>
any help ....

djr33
02-21-2010, 12:44 AM
This line doesn't work:
echo gregoriantojd($endDate)-gregoriantojd($startDate)=gregoriantojd($date);

You need:
echo gregoriantojd($endDate).'-'.gregoriantojd($startDate).'='.gregoriantojd($date);


Before you were using actual code: you were performing this math: a-b (so you get 3-2, which is 1), then you are SETTING x=y-- that means set X to Y.
So you were trying to set 1 (or whatever number) to the output of the function. Or, if the parsing order is = first then -, it would be trying to set the function itself to that function's output, giving a very strange error-- which is I think what you got.
Only variables (as far as I've ever seen) can be set:
$x = 5;

But doing
func(x) = func(y);
will cause a weird error.


By putting it in quotes, then you are outputting strings (text) rather than processing code.

zee000
02-22-2010, 06:09 AM
thanks for your information

but i got this error

Warning: gregoriantojd() expects exactly 3 parameters, 1 given in

Warning: gregoriantojd() expects exactly 3 parameters, 1 given in

djr33
02-22-2010, 09:25 AM
The first error was a major error-- it didn't know how to start processing the code.

The next one is a specific error to how this code is written.

A function takes a specific number of arguments. For example, echo() takes 1: echo($text).
Others take many more arguments.
It entirely depends on the function.

When a certain number of arguments are expected and NOT sent, or if too many are sent, an error will occur. Just change to the right number of arguments and you will be fine:
instead of func($a), you need func($a,$b,$c).

I have no idea what $b and $c are here, because I don't know what that function is/does. You need to find documentation on it or find where it is defined in your code and then look to see what those values should be.