News:

The "Support Requests" forum is now viewable by guests.

Main Menu

WHY THE HELL IS THIS SCRIP RUNNING WHEN THE IF REQS AREN'T MET!?!??!?

Started by sixthcrusifix, January 20, 2006, 03:25:00 AM

Previous topic - Next topic

sixthcrusifix

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!");}


?>

Visite me website at http://www.sixthcrusifix.com

admin

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

brainiac744

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!");
}


?>

webzone (archived)


brainiac744

Sure, that works too :) (Just for my information, aren't those both basically 2 different ways of achieving the same effect?)

webzone (archived)

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 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.

sixthcrusifix

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 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
Visite me website at http://www.sixthcrusifix.com

webzone (archived)

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 ";}
?>

sixthcrusifix

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 . . .
Visite me website at http://www.sixthcrusifix.com

webzone (archived)

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.