EffectU Posted February 15, 2009 Share Posted February 15, 2009 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 = "alex@effectu.nl"; $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 Quote Link to comment https://forums.phpfreaks.com/topic/145289-fatal-error-cant-use-function-return-value-in-write-context-in-dwwwrooteffe/ Share on other sites More sharing options...
Mchl Posted February 15, 2009 Share Posted February 15, 2009 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; } Quote Link to comment https://forums.phpfreaks.com/topic/145289-fatal-error-cant-use-function-return-value-in-write-context-in-dwwwrooteffe/#findComment-762731 Share on other sites More sharing options...
RichardRotterdam Posted February 15, 2009 Share Posted February 15, 2009 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; Quote Link to comment https://forums.phpfreaks.com/topic/145289-fatal-error-cant-use-function-return-value-in-write-context-in-dwwwrooteffe/#findComment-762734 Share on other sites More sharing options...
Mchl Posted February 15, 2009 Share Posted February 15, 2009 What the...? You sure it's correct syntax Dj Kat? Can't find anything about it in documentation Quote Link to comment https://forums.phpfreaks.com/topic/145289-fatal-error-cant-use-function-return-value-in-write-context-in-dwwwrooteffe/#findComment-762749 Share on other sites More sharing options...
RichardRotterdam Posted February 15, 2009 Share Posted February 15, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/145289-fatal-error-cant-use-function-return-value-in-write-context-in-dwwwrooteffe/#findComment-762764 Share on other sites More sharing options...
Mchl Posted February 15, 2009 Share Posted February 15, 2009 Well... there it is... not that I like it... Quote Link to comment https://forums.phpfreaks.com/topic/145289-fatal-error-cant-use-function-return-value-in-write-context-in-dwwwrooteffe/#findComment-762766 Share on other sites More sharing options...
RichardRotterdam Posted February 15, 2009 Share Posted February 15, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/145289-fatal-error-cant-use-function-return-value-in-write-context-in-dwwwrooteffe/#findComment-762774 Share on other sites More sharing options...
Mchl Posted February 15, 2009 Share Posted February 15, 2009 I've no HTML in my code Quote Link to comment https://forums.phpfreaks.com/topic/145289-fatal-error-cant-use-function-return-value-in-write-context-in-dwwwrooteffe/#findComment-762799 Share on other sites More sharing options...
Daniel0 Posted February 15, 2009 Share Posted February 15, 2009 I've no HTML in my code You're going to have to mix it some time. How else would you iterate over an array to output each element for instance? Quote Link to comment https://forums.phpfreaks.com/topic/145289-fatal-error-cant-use-function-return-value-in-write-context-in-dwwwrooteffe/#findComment-762821 Share on other sites More sharing options...
Mchl Posted February 15, 2009 Share Posted February 15, 2009 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) Quote Link to comment https://forums.phpfreaks.com/topic/145289-fatal-error-cant-use-function-return-value-in-write-context-in-dwwwrooteffe/#findComment-762824 Share on other sites More sharing options...
Daniel0 Posted February 15, 2009 Share Posted February 15, 2009 template engines help a lot though Then you'll just be mixing another language than PHP with HTML. I don't see the point in that. Quote Link to comment https://forums.phpfreaks.com/topic/145289-fatal-error-cant-use-function-return-value-in-write-context-in-dwwwrooteffe/#findComment-762827 Share on other sites More sharing options...
Mchl Posted February 15, 2009 Share Posted February 15, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/145289-fatal-error-cant-use-function-return-value-in-write-context-in-dwwwrooteffe/#findComment-762838 Share on other sites More sharing options...
Daniel0 Posted February 15, 2009 Share Posted February 15, 2009 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). Quote Link to comment https://forums.phpfreaks.com/topic/145289-fatal-error-cant-use-function-return-value-in-write-context-in-dwwwrooteffe/#findComment-762858 Share on other sites More sharing options...
Mchl Posted February 15, 2009 Share Posted February 15, 2009 Well... I'm lacking in discipline, and proper application design is not my strong point Quote Link to comment https://forums.phpfreaks.com/topic/145289-fatal-error-cant-use-function-return-value-in-write-context-in-dwwwrooteffe/#findComment-762864 Share on other sites More sharing options...
bothwell Posted February 15, 2009 Share Posted February 15, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/145289-fatal-error-cant-use-function-return-value-in-write-context-in-dwwwrooteffe/#findComment-762895 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.