...

View Full Version : if else



romalong
11-09-2003, 11:06 PM
why if i submit my form blank i have message like: been mailed to roma?



<?
if ($button==roma){
$to="x@x.net";
}else{
$to="y@y.net";
}
$message = stripslashes($_POST['message']);
if (isset($message)){
$check = mail($to,"",$message,"From: _@{$_SERVER['REMOTE_ADDR']}\r\n");
if($check) {
echo $message.'<br/>been mailed to '.$button;
}else{
echo '<div class=error>unable to send sms!</div>';
}
}else{
echo '<div class=error>xxxx happens</div>';
}
?>

mordred
11-09-2003, 11:14 PM
Because you can send blank emails and the $check is set to 1 (or true?) whenever the mail was successfully sent. The next line, you check if $check evaluates to "true", and when then mail has been sent, you print the $message variable, but it's blank, and so you only get " been sent to roma".

maltrecho
11-09-2003, 11:19 PM
Why don't you try?:
if (!empty($message)) {

romalong
11-10-2003, 12:01 AM
aha!

isset() isn't appropriate in my case because it returns TRUE even if it's empty, isn't it? but if i use empty(), then i can do more precise check. am i right?
so the code would be:



<?
if ($button==roma){
$to="x@x.net";
}else{
$to="y@y..net";
}
$message = stripslashes($_POST['message']);
if (!empty($message)){
$check = mail($to,"",$message,"From: _@{$_SERVER['REMOTE_ADDR']}\r\n");
if($check) {
echo "<div class=bdr>$message. <br/>been mailed to .$to</div>";
}else{
echo '<div class=error>unable to send sms!</div>';
}
}else{
echo '<div class=error>**** happens</div>';
}
?>

romalong
11-10-2003, 12:05 AM
and now if i leave the form empty i have 'xxxx happens'

ReadMe.txt
11-16-2003, 08:48 PM
er yeah, thats what you should get. Did you read the code at all?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum