-1
<?php
$campaign = $_GET['campaign'];
$straightlink = "https://link1";
$sublink = "https://link2";
if ($campaign = "1234abc"){
 $link = $sublink;}
else { $link = $straightlink;}
?>

I'm testing this code with echoecho $link and the output is always link2

I need link2 to echo when campaign matches the string and link1 to appear in any other situation.

imbg
  • 1

1 Answers1

0

You need to quantify with a true statement or a truthy statement. You are setting something equal to === vs == vs =

=      Sets a variable "equal to"
==    Truthy -- 1 and '1' are treated as "equals"
===  Truth -- 1 and '1' and NOT the same -- Will return false

Also it is worth noting you need an elseif when you have a second query -- Which I created a fake one so you can view the syntax. elseif( $link == 'abcdefghi')

<?php
    $campaign = $_GET['campaign'];
    $straightlink = "https://link1";
    $sublink = "https://link2";
    
    if ($campaign === "1234abc"){
        $link = $sublink;
    }
    elseif( $link == 'abcdefghi') { 
        // Do something 
    }else{
        $link = $straightlink
    }
Zak
  • 6,976
  • 2
  • 26
  • 48