开发者

why isn't strlen working?

strlen($_POST["link"]) > 5 ? $link = $_POST["link"] : $errormsg .= "Please enter a link for the article.<br />";
strlen($_POST["img_link"]) > 5 ? $img_link = 开发者_开发问答$_POST["img_link"] : $errormsg .= "Please enter a image link for the article.<br />";
echo $errormsg;

the error message is always empty, no matter what the input is.


You are using ternary operator, but in the same time, you are making spaghetti out of your error messages. Doesn't go that way :)

if(strlen($_POST["link"]) > 5){
    $link = $_POST["link"];
}else{
    $errors[] = "Please enter a link for the article.";
}


Try this:

strlen($_POST["link"]) > 5 ? ($link = $_POST["link"]) : ($errormsg .= "Please enter a link for the article.<br />");
strlen($_POST["img_link"]) > 5 ? ($img_link = $_POST["img_link"]) : ($errormsg .= "Please enter a image link for the article.<br />");
echo $errormsg;

The ternary operator has a higher precedence than the assignment operator.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜