-1
                <?php 

                if ($user->getProfile()->get('title')="Canon"); {
                echo "Test1"; }
                else {
                echo "Test2"; }

                ?>

This is causing my site to break, is there an obvious mistake? Thank you.

4 Answers4

6

= is an assignment, you want == for a comparison.

You also shouldn't have a ; between ) and {.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
0

This will work:

  <?php 

            if ( ($user->getProfile()->get('title')) == "Canon" ){ 
              echo "Test1";
            }
            else {
            echo "Test2"; 
            }

            ?>

First of all You need a comparison '==' and not an assigning '='

And then You have a syntax error with a ';' after the condition

Gan
  • 164
  • 1
  • 4
  • 13
0

You need to change the = sign to == as the first one assigns a values while the latter one compares it.

And also, you don't need to terminate the if statement with a semicolon

if ($user->getProfile()->get('title') == "Canon") /* note that there is no semicolon here */ 
{ echo "Test1"; }
            else 
{ echo "Test2"; }
Alex Szabo
  • 3,274
  • 2
  • 18
  • 30
0
            <?php 

            if ($user->getProfile()->get('title')=="Canon") {
                echo "Test1"; 
            }

            else {
                echo "Test2"; 
            }


            ?>

Try this.

user3849925
  • 31
  • 1
  • 5