-1

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

}
JA4677
  • 331
  • 2
  • 5
  • 11

2 Answers2

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

//give warning if bad words are used

}?>

use it like this

Vivek Singh
  • 2,435
  • 1
  • 12
  • 24
0

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

}