1

I'm having an issue with some PHP code where my page is crashing whenever i insert the following code.

Revised Code

 $supp = emb_meta( "_emb_supplier" ); 

if ($supp == "Type1") {
    echo '<a href="http://link.com/" target="_blank">Text here for Type1! product.</a>';
} 
elseif ($supp == "Type2") {
    echo '<a href="http://link.com/" target="_blank">Text here for Type2 product.</a>';
}
elseif ($supp == "Type3") {
    echo '<a href="http://link.com/" target="_blank">Text here for Type3 product.</a>';
}
elseif ($supp == "Type4"){
    echo '<a href="http://link.com/" target="_blank">Text here for Type4 product.</a>';
}
else {
    echo '';
}
?>
3
  • 1
    Is there an error appearing?If so, what does it say? Commented Mar 6, 2017 at 3:07
  • The whole page doesn't render unfortunately. I was wondering if my variables are not working correctly. Commented Mar 6, 2017 at 3:08
  • 1
    Instead of $supp = emb_meta( "_emb_supplier" ); just set $supp = "Type1"; and see what happens. Maybe emb_meta is unknown here Commented Mar 6, 2017 at 3:15

3 Answers 3

1
elseif {$supp == "Type4"

This syntactically incorrect. It should be:

elseif ($supp == "Type4"){

Also you should add a ; behind each echo statement, although I guess this won't be the problem here

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks that is incorrect but still getting the error after the correction.
Did you add the ;? Maybe you update your question to the current code that still won't work
0

please put ; after each statement and correct elseif($supp == "Type4")

    $supp = emb_meta( "_emb_supplier" ); 

    if ($supp == "Type1") {
        echo '<a href="http://l...content-available-to-author-only...k.com/" target="_blank">Text here for Type1! product.</a>';
    } 
    elseif ($supp == "Type2") {
        echo '<a href="http://l...content-available-to-author-only...k.com/" target="_blank">Text here for Type2 product.</a>';
    }
    elseif ($supp == "Type3") {
        echo '<a href="http://l...content-available-to-author-only...k.com/" target="_blank">Text here for Type3 product.</a>';
    }
    elseif ($supp == "Type4"){

        echo '<a href="http://l...content-available-to-author-only...k.com/" target="_blank">Text here for Type4 product.</a>';
    }
    else {
        echo '';
    }

3 Comments

Tried the code update but still getting nothing else rendering on the page.
use $supp = "Type1"; instead of $supp = emb_meta( "_emb_supplier" ); and see what happend
Yes i tried that and the rest of the code works perfectly. the issue is that equating the variable to emb_meta isn't working and i'm not sure why.
0

Haven't programmed in PHP for ages. But I think you're missing some semicolons there.

I'm like 50% sure.

It's possible you don't need a semi-colon cause it is the last operation, but try adding semicolons to your if blocks.

5 Comments

The semicolon won't be the issue. There is a mistake in the syntax at "Type4"
I see. I agree. The syntax error there is definitely the culprit. How would you recommend people normally debug a "page won't load" error? If they tried running it from the command line would they get a message about the syntax error? I suppose maybe apache logs might show info too.
Correct, there is. In the error log you would see what is the issue. Sometimes you find a special php error log in /var/log
I also recomend to never use "==" operator. It complitly broken in php. Use "===" instead.
Ok the issue is with that first expression. I tried changing the expression $supp = emb_meta( "_emb_supplier" ); to $supp = "Type1"; and everything worked to perfection! The issue now is to determine why that first expression isn't transferring to the variable correctly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.