if(defined($_POST["message"]) && defined($_POST["name"]))
{
In that if block an exception is thrown constantly. I am looking for a function that will 开发者_如何转开发prevent this by testing if it the post variable exists..if it doesnt exists return false instead of throwing an exception
if (isset($_POST["message"]) && isset($_POST["name"])) {
// ....
}
or if you want to check them to be not only set but also non-empty:
if (!empty($_POST["message"]) && !empty($_POST["name"])) {
// ....
}
Use isset()
for determining if a variable is set. Use defined()
to check if a constant is defined with the define()
function.
See the Manual:
defined function
isset function
Use isset
instead of defined
.
if(isset($_POST["message"]) && isset($_POST["name"])) {
[...]
defined
takes a string as an argument, and is for checking if a constant exists.
精彩评论