6 replies
Does anyone see the error in this snippet?

PHP Code:
function get_phone_number() {

if (isset(
$_COOKIE['Believe_Adwords'])) echo "555-0968-5566";

else echo 
"555-8979-4567";


I'm getting:

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/poison1/public_html/wp-content/themes/thesis_17/custom/custom_functions.php on line 51
I got the code from this site and I've tried both the way it was written $_COOKIE['Believe_Adwords] and the way I thought it should be written $_COOKIE['Believe_Adwords'] both without success.

Any input is appreciated!
#bad #code
  • Profile picture of the author Tom B
    Banned
    Looks like you are missing some {} in your if statement.
    {{ DiscussionBoard.errors[2348597].message }}
    • Profile picture of the author sdwrage
      I never understood ones need to avoid braces so much. I notice a lot of coders coming over from other languages do it a lot.
      {{ DiscussionBoard.errors[2348658].message }}
  • Profile picture of the author ocsSEO01
    Banned
    [DELETED]
    {{ DiscussionBoard.errors[2348680].message }}
    • Profile picture of the author CarloD.
      function get_phone_number()
      {
      if (isset($_COOKIE['Believe_Adwords'])) {
      echo "555-0968-5566";
      } else {
      echo "555-8979-4567";
      }
      }
      Signature

      {{ DiscussionBoard.errors[2348892].message }}
      • Profile picture of the author vulcanscripts
        The problem with the original snippet is the use of opening speech marks instead of single or double quotes. Surrounding the conditional statements with left and right curly brackets is not required, unless of course there is more than one line of code to execute. As this function is so basic (probably too basic to even be a function) I myself would use an alternative syntax to the control structure as follows:

        PHP Code:
        function get_phone_number() {

            echo (isset(
        $_COOKIE['Believe_Adwords'])) ? '555-0968-5566' '555-8979-4567';


        However, in my opinion (unless it causes performance issues) there is no right or wrong way to do things in php, just so long as your code works as intended! The fix by "CarloD." above will work just fine and will be much easier to understand for most! The reason for my post is really only to clear up some inaccuracies in this thread and explain the actual problem, as opposed to just providing a fix. After all, this is programming talk!
        Signature
        Live Track Mobile Spy - Android Spy Software
        Postcode Palâ„¢
        - Geo Datasets for GB, NI, CI and the Isle of Man
        {{ DiscussionBoard.errors[2350284].message }}
        • Profile picture of the author CarloD.
          ...heh Ya I was lazy and it was pretty well 3 in the AM.
          Signature

          {{ DiscussionBoard.errors[2350413].message }}

Trending Topics