skip to Main Content

I wonder what’s wrong with this code:

if ( isset( $_POST['add-to-cart'] ) ) && $matched_id = (int) $_POST['add-to-cart'] ) {            
      $url = 'https://website.com/cart/?add-to-cart=363053'; 
    }

It returned a syntax error, unexpected ‘&&’ (T_BOOLEAN_AND)

2

Answers


  1. You missed some brackets…

    Try adding brackets like :

    if ( (isset( $_POST['add-to-cart'])) && ($matched_id = (int) $_POST['add-to-cart']) ) {            
      $url = 'https://website.com/cart/?add-to-cart=363053'; 
    }else{
        echo "Error";
    }
    

    Or removing some brackets like :

    if ( isset( $_POST['add-to-cart'] )  && $matched_id = (int) $_POST['add-to-cart'] ) {            
      $url = 'https://website.com/cart/?add-to-cart=363053'; 
    }else{
        echo "Error";
    }
    

    Remove following part from example I have given when issue fixed…

    else{
        echo "Error";
    }
    
    Login or Signup to reply.
  2. if ( isset( $_POST['add-to-cart'] ) && $matched_id = (int) $_POST['add-to-cart'] ) { $url = 'https://website.com/cart/?add-to-cart=363053'; }
    I think that you have to remove the bracket.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search