当前位置: 动力学知识库 > 问答 > 编程问答 >

php - IF with multiple conditions not working

问题描述:

I am trying to create an if statement with multiple conditions but it won't work and perhaps it is my syntax.

I have two post variables, which both give me the value fine elsewhere on my page. They are:

$_POST['text']

$_POST['rating'] //can be G, PG or R

What I am trying to do is make my word filter code work only if the rating equals "G"

What is currently happening though is that the filter is flagging a bad word regardless of the rating and ignoring my IF rating = G part.

if (isset($_POST['text']) and $_POST['rating'] = "G") {

//give warning if bad words are used

}

网友答案:
<?php 
if (isset($_POST['text']) && $_POST['rating'] =="G") {

//give warning if bad words are used

}?>

use it like this

网友答案:

You may also use the symbol version of the syntax.

  • && for and
  • || for or

Also, = does not mean equals in an if statement. That is the syntax for setting a variable. You would say == (equals to).

To say "not equals" you would use != or !=

if (isset($_POST['text']) && $_POST['rating'] ==  "G") {

//give warning if bad words are used

}
分享给朋友:
您可能感兴趣的文章:
随机阅读: