View Full Version : if statement question
Jon W
01-06-2008, 09:20 PM
Alright, well here in my script I'm trying to check and see if a value it filled and if the values both match. For some reason I'm getting a error message with this line of code though. (I thought it was a pretty sample line of script)
<?php if(!empty($_POST['Password'])) && ($_POST['Comfirmed_password']) == ($_POST['Password']) { echo($_POST['Comfirmed_password']); } else { echo ''; } ?>
By the way this is going inside of a value you tag.
Thanks for the help
And as a side question, which I know is going to be one of the next questions that I ask.... How can I make a Random key for the User name? I saw it in some login script that it creates a random key, but not to sure how to make the function or whatever to make the random key. Heres the site that I was looking off of: http://www.roscripts.com/PHP_login_script-143.html
Jon W
oesxyl
01-06-2008, 09:30 PM
Alright, well here in my script I'm trying to check and see if a value it filled and if the values both match. For some reason I'm getting a error message with this line of code though. (I thought it was a pretty sample line of script)
<?php if(!empty($_POST['Password'])) && ($_POST['Comfirmed_password']) == ($_POST['Password']) { echo($_POST['Comfirmed_password']); } else { echo ''; } ?>
By the way this is going inside of a value you tag.
Thanks for the help
Jon W
<?php
if(isset($_POST['Password']) &&
isset($_POST['Comfirmed_password']) &&
!empty($_POST['Password'])) &&
!empty($_POST['Comfirmed_password']) &&
$_POST['Comfirmed_password'] === $_POST['Password']) {
echo($_POST['Comfirmed_password']);
} else {
echo 'no match';
}
?>
- note the === instead of == and filled message in else branch
probably empty(...) is useless, but check the php manual, I can't remember now and I have not time to check myself, when empty return false? ( sure if is '', but when x is unset, empty(x) is true?) AFAIK if a value in a form is not filled POST for that value is unset, check this too.
best regards
matak
01-06-2008, 09:47 PM
i think someone mentioned that it's good to use strlen() or similar in these situations. then you can limit minimum to let's say 4 characters.
i'm not sure is this what you asked, but it can be usefull anyway
Inigoesdr
01-06-2008, 10:07 PM
probably empty(...) is useless, but check the php manual, I can't remember now and I have not time to check myself, when empty return false? ( sure if is '', but when x is unset, empty(x) is true?)
Any value that equals false('', NULL, 0) or if it's not set will return true. So as long as you aren't expecting a 0 for your form input it should work fine.
AFAIK if a value in a form is not filled POST for that value is unset, check this too.
Nope, even if it's blank it will still be set in the $_POST array.
oesxyl
01-06-2008, 10:21 PM
Any value that equals false('', NULL, 0) or if it's not set will return true. So as long as you aren't expecting a 0 for your form input it should work fine.
Nope, even if it's blank it will still be set in the $_POST array.
do you mean blank as space+, not "not filled with anything", isn't it?
in last case, print_r($_POST), echo a [field name] => '' item?
best regards.
Inigoesdr
01-06-2008, 11:21 PM
do you mean blank as space+, not "not filled with anything", isn't it?
in last case, print_r($_POST), echo a [field name] => '' item?
If you have a form such as this:
<form action="test.php" method="post">
<input type="text" name="test" />
<input type="submit" />
</form>
And you submit it without anything in the text field, the $_POST array will be array('test' => '');
oesxyl
01-06-2008, 11:31 PM
If you have a form such as this:
<form action="test.php" method="post">
<input type="text" name="test" />
<input type="submit" />
</form>
And you submit it without anything in the text field, the $_POST array will be array('test' => '');
thanks, :), I hope you don't west your time to test this, a simple yes was enough, :). Usualy when I'm not sure about something I test myself, I ask only because I have not enough time for this and I was curios about the result even is not important for me in this moment.
best regards
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.