PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
This is a really bad way of testing if a field was provided... The part where you see if(!$_POST[...]){ creates what we call a positive assertion if i do not name it wrongly...
Negative assertions
'', 0, NULL, false
Positive assertions
- anything that has a value
- true
- !NULL
So in this case, checking for each field in the post if it has a value creates a positive/negative assertion. By reversing the assertion using !, you create a weak testing mechanism to see if a value was submitted. If not, it sets a warning that a field was not provided.
I understood your explanation but I cant figure out how it works on this code.
Logically, when the "if (!$_POST[$blabla])" is evaluadted:
1. $blabla exists because $blabla has a value so $blabla is true;
2. the ! is there so the !$_POST[$blabla] is false;
3. so if (!$_POST[$blabla]) results false.
If it is getting into the IF statement then obviously $_POST[$blabla] does not return a value. Try outputting the variable before the IF statement to see what it says.
Wait just there, your code should check errors or missing fields. If you do provide values to that script it will not return warnings, if don't send values it will send back warnings...
Yes, i see now. "echo $_POST[$blabla];" returns Null.
But... what Ive found interesting is that if it runs within a debugger(phpDesigner)
and i goes through step by step, the (!$_POST[$field]) shows the "name" value.
And this is a bit misleading.
Thanks for helping.