Jump to content

Fatal error: Can't use function return value in write context in D:\WWWRoot\effe


EffectU

Recommended Posts

I'm trying to write an email.php script for my website: www.effectu.nl

 

Now i'm getting this error and do not know what to do with it.

 

<?//preferences
$message->to = "[email protected]";
$message->ref = "effectu.nl";

//check for POST and form send from effectu.nl
if($_POST&&preg_match("#".$message->ref."#i",$_SERVER['HTTP_REFERER'])):

$message->send=true;

function sanitize($input) {
    return ucfirst(trim(strip_tags($input)));
}

//check and sanitize POST fields
if(!empty(sanitize($_POST['name1'])))$data->name1=sanitize($_POST['name1']);
else $message->send=false;

if(!empty(sanitize($_POST['company'])))$data->company=sanitize($_POST['company']);
else $message->send=false;

if(!empty(sanitize($_POST['email'])))$data->email=sanitize($_POST['email']);
else $message->send=false;

if(!empty(sanitize($_POST['number'])))$data->number=sanitize($_POST['number']);
else $message->send=false;

if(!empty(sanitize($_POST['fax'])))$data->website=sanitize($_POST['fax']);
else $message->send=false;

if(!empty(sanitize($_POST['message1'])))$data->message1=sanitize($_POST['message1']);
else $message->send=false;

//if all POST fields are not empty, send!
if($message->send):

	//construction of the email
	$message->subject	= $data->name." stuurde een bericht vanaf effectu.nl";
	$message->headers = "From: ".$data->email." \r\n".
	"Reply-To: ".$message->to."\r\n".
	"X-Mailer: PHP/".phpversion();
	$message->message 	.= "Bericht verstuurd vanaf www.effectu.nl \r\n\r\n";
	$message->message 	.= "Naam: ".$data->name1." \r\n";
	$message->message 	.= "Bedrijf: ".$data->company." \r\n";
	$message->message 	.= "Email: ".$data->email." \r\n";
	$message->message 	.= "Telefoon: ".$data->phone." \r\n";
	$message->message 	.= "Website: ".$data->website." \r\n\r\n";
	$message->message 	.= "Bericht: ".$data->message1." \r\n";

	//send the email
	mail($message->to, $message->subject, $message->message, $message->headers);

endif;

endif;?>

 

Does anyone know the solution?

The problem is in this line

 

if(!empty(sanitize($_POST['name1'])))$data->name1=sanitize($_POST['name1']);

 

thankz!!!

alex

I might be wrong, but I think that when using if else, you have to use brackets {}

 

if(!empty(sanitize($_POST['name1']))) {
$data->name1=sanitize($_POST['name1']);
}else {
$message->send=false;
}

I might be wrong, but I think that when using if else, you have to use brackets {}

 

if(!empty(sanitize($_POST['name1']))) {
$data->name1=sanitize($_POST['name1']);
}else {
$message->send=false;
}

Using curly brackets in this is probably a better option.

You are using an alternative if else syntax.

so if you use and alternative if else you should not place the semicolon after the if line. instead use :

if($condition):
  //output if
else:
  //output else
endif;

 

 

I'm pretty sure or you could simply test it.

have a look on the manual elseif and look at the second code block.

It also would make sense if you compare it to python syntax

Well... there it is... not that I like it...

Well most cases I dislike that syntax too. How ever if you use it where there is a lot of html between it, then the readability does improve. That and I had less complaints from the designers who read my code.

I json_encode it :)

 

Ok. I said it a bit tongue in the cheek. The app I spend most of the time on has GUI created with ExtJS and gets all data from server by Ajax requests.

 

I know that sometimes mixing PHP with HTML is close to unevitable (template engines help a lot though)

Point is: they make you mix those in files separated from business logic. Sure, I can split my code myself without template engines... but template engine is like having someone watching over you, so that you don't take any shortcuts.

I just don't see the point in e.g. (Smarty):

<ul>
{foreach from=$myArray item=foo}
<li>{$foo}</li>
{/foreach}
</ul>

instead of

<ul>
<?php foreach ($myArray as $foo): ?>
<li><?php echo $foo ?></li>
<?php endforeach ?>
</ul>

 

With discipline and proper app design it shouldn't be a problem to keep it separated (and enforce it separated).

I just don't see the point in e.g. (Smarty):

<ul>
{foreach from=$myArray item=foo}
<li>{$foo}</li>
{/foreach}
</ul>

instead of

<ul>
<?php foreach ($myArray as $foo): ?>
<li><?php echo $foo ?></li>
<?php endforeach ?>
</ul>

 

With discipline and proper app design it shouldn't be a problem to keep it separated (and enforce it separated).

 

I'm really glad to see somebody say this. I've been harbouring a dirty little non-templating secret for a long time now and whenever I point out that I actually don't really feel like using a templating language to do exactly the same thing as ordinary PHP would do, I get howls of derision from Rails programmers ;)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.