For some reason even if you input NOTHING into the form fields as long as you push submit the script runs as if all the fields were set to something.
<?php
if(!isset($_POST['name'],$_POST['games'],$_POST['reason'])){
//nothing, everything's just starting.
echo("TEST");
}else if(isset($_POST['name'],$_POST['games'],$_POST['reason'])){
$name_ = $_POST['name']; $games_ = $_POST['games']; $reason_ = $_POST['reason'];
echo("$name_ $games_ $reason_");
$msg = "Account Name: $name_ \n";
$msg .= "Games Made: $games_ \n";
$msg .= "Reason: $reason_ \n";
$to = "join_pro@gdmail.com";
$sub = "Account Request";
mail($to,$sub,$msg) ;
echo("<script> alert(\"SUCCESS! Account request mailed!\")</script>");
} else{echo("You Left Out A Field!");}
?>
This is because you are only testing if the variables exist. Even if the input is blank, the variable itself still exists.
Thank you,
FreePgs.com Admin
Try something like this:
<?php
if ($_POST['name'] != "" && $_POST['games'] != "" && $_POST['reason'] != "") {
$name_ = $_POST['name'];
$games_ = $_POST['games'];
$reason_ = $_POST['reason'];
echo("$name_ $games_ $reason_");
$msg = "Account Name: $name_ \n";
$msg .= "Games Made: $games_ \n";
$msg .= "Reason: $reason_ \n";
$to = "join_pro@gdmail.com";
$sub = "Account Request";
mail($to,$sub,$msg) ;
echo("<script> alert(\"SUCCESS! Account request mailed!\")</script>");
}
else {
echo("You Left Out A Field!");
}
?>
Quote$_POST['name'] != ""
Why not :
!empty($_POST['name'])
Sure, that works too :) (Just for my information, aren't those both basically 2 different ways of achieving the same effect?)
Quotearen't those both basically 2 different ways of achieving the same effect?
I'm not sure, but the PHP documentation makes me think that empty (http://php.net/function.empty) is a more complete check.
QuoteThe following things are considered to be empty:
"" (an empty string)
0 (0 as an integer)
"0" (0 as a string)
NULL
FALSE
array() (an empty array)
var $var; (a variable declared, but without a value in a class)
In any case, empty() is more meaningful when reviewing the code, IMO. This is why I tend to use it.
Quote from: webzone on January 20, 2006, 04:19:18 AM
Quotearen't those both basically 2 different ways of achieving the same effect?
I'm not sure, but the PHP documentation makes me think that empty (http://php.net/function.empty) is a more complete check.
QuoteThe following things are considered to be empty:
"" (an empty string)
0 (0 as an integer)
"0" (0 as a string)
NULL
FALSE
array() (an empty array)
var $var; (a variable declared, but without a value in a class)
In any case, empty() is more meaningful when reviewing the code, IMO. This is why I tend to use it.
oh thanks. isset always used to work for me I dunno why this is differnt. I think i'll start using empty. :D
isset checks if the variable was set, even if it was set of an empty value. empty will check if the variable contains something non-empty.
for instance, this code should display "TRUE FALSE" (ie. isset returned true and !empty returned false).
<?php
$some_var = "";
if(isset($some_var)){ echo "TRUE "; }else{ echo "FALSE ";}
if(!empty($some_var)){ echo "TRUE "; }else{ echo "FALSE ";}
?>
Quote from: webzone on January 20, 2006, 08:01:47 PM
isset checks if the variable was set, even if it was set of an empty value. empty will check if the variable contains something non-empty.
for instance, this code should display "TRUE FALSE" (ie. isset returned true and !empty returned false).
<?php
$some_var = "";
if(isset($some_var)){ echo "TRUE "; }else{ echo "FALSE ";}
if(!empty($some_var)){ echo "TRUE "; }else{ echo "FALSE ";}
?>
Will empty return an error if the variable wasn't set at all? This gets a bit wacky. I don't wanna have to use both . . .
empty() checks if the variable is empty or if it wasn't set at all. so, it will work even if the variable was never created.
to my knowledge, only very few functions in PHP generate an error if they receive an empty variable.